Skip to content

Commit

Permalink
Re-add docker justfile recipes and move Dockerfile to root dir
Browse files Browse the repository at this point in the history
  • Loading branch information
cluttrdev committed Jan 25, 2024
1 parent 5560891 commit 0b01c7b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
!main.go
!cmd/
!pkg/
!grpc/
!internal/
12 changes: 7 additions & 5 deletions build/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# BUILD
#

FROM docker.io/golang:1.20-alpine3.18 AS build
ARG GOVERSION=1.21

FROM docker.io/golang:${GOVERSION}-alpine AS build

RUN apk add --update --no-cache ca-certificates

Expand All @@ -14,7 +16,7 @@ RUN adduser \
--home /nonexistent \
--no-create-home \
--gecos "" \
glche
user

WORKDIR /build

Expand All @@ -29,8 +31,8 @@ ARG GOARCH=amd64
ARG VERSION=v0.0.0+unknown

RUN GOOS=${GOOS} GOARCH=${GOARCH} go build \
-o /bin/gitlab-exporter \
-ldflags "-X 'main.version=${VERSION}' -s -w"
-ldflags "-X 'main.version=${VERSION}' -s -w" \
-o /bin/gitlab-exporter

#
# RUN
Expand All @@ -44,7 +46,7 @@ COPY --from=build /etc/group /etc/group

COPY --from=build /bin/gitlab-exporter /bin/gitlab-exporter

USER glche:glche
USER user:user

ENTRYPOINT [ "/bin/gitlab-exporter" ]

Expand Down
60 changes: 58 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ BIN_NAME := `basename {{GIT_DIR}}`
BIN_DIR := "bin"
DIST_DIR := "dist"

GITHUB_OWNER := "cluttrdev"
GITHUB_REPO := "gitlab-exporter"

# list available recipes
default:
@just --list
Expand Down Expand Up @@ -32,8 +35,8 @@ dist *args="":
# create a new release
release *args="":
#!/bin/sh
export GITHUB_OWNER=cluttrdev
export GITHUB_REPO=gitlab-exporter
export GITHUB_OWNER={{GITHUB_OWNER}}
export GITHUB_REPO={{GITHUB_REPO}}
{{GIT_DIR}}/scripts/release.sh -p {{MAIN}} {{args}}

changes from="" to="":
Expand All @@ -52,3 +55,56 @@ clean:
@rm {{DIST_DIR}}/{{BIN_NAME}}_* 2>/dev/null || true
@-[ -d {{DIST_DIR}} ] && rmdir {{DIST_DIR}}

###############################################################################

docker-build:
#!/bin/sh

github_owner={{GITHUB_OWNER}}
github_repo={{GITHUB_REPO}}
git_dir={{GIT_DIR}}

set -eu

source ${git_dir}/scripts/functions.sh

image=${github_owner}/${github_repo}
version=$(get_version)
if is_dirty; then
version="${version}-modified"
fi

docker build \
-f Dockerfile \
--build-arg VERSION=${version} \
-t ${image}:${version} \
.

if is_tagged; then
docker tag ${image}:${version} ${image}:latest
fi

docker-push: docker-build
#!/bin/sh

github_owner={{GITHUB_OWNER}}
github_owner={{GITHUB_REPO}}
git_dir={{GIT_DIR}}

set -eu

source ${git_dir}/scripts/functions.sh

if is_dirty; then
echo "Working diretory is dirty"
exit 1
fi

image=${github_owner}/${github_repo}
version=$(get_version)

docker push ${image}:${version}

if is_tagged; then
docker push ${image}:latest
fi
3 changes: 3 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ scriptsdir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
source "${scriptsdir}/functions.sh"

version=$(get_version)
if is_dirty; then
version="${version}-modified"
fi
commit_sha=$(get_commit_sha)
commit_date=$(get_commit_date)

Expand Down
3 changes: 3 additions & 0 deletions scripts/dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ if [ -z "${bin_name}" ]; then
fi

version=$(get_version)
if is_dirty; then
version="${version}-modified"
fi

declare -A OSARCHMAP=(
[linux]="amd64,arm,arm64"
Expand Down

0 comments on commit 0b01c7b

Please sign in to comment.