From 0b01c7b961309f9fc9380bdba33aee81551accab Mon Sep 17 00:00:00 2001 From: cluttrdev Date: Wed, 24 Jan 2024 21:13:29 +0100 Subject: [PATCH] Re-add docker justfile recipes and move Dockerfile to root dir --- .dockerignore | 1 + build/Dockerfile => Dockerfile | 12 ++++--- justfile | 60 ++++++++++++++++++++++++++++++++-- scripts/build.sh | 3 ++ scripts/dist.sh | 3 ++ 5 files changed, 72 insertions(+), 7 deletions(-) rename build/Dockerfile => Dockerfile (80%) diff --git a/.dockerignore b/.dockerignore index ad51cf5..b3c29dd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -11,4 +11,5 @@ !main.go !cmd/ !pkg/ +!grpc/ !internal/ diff --git a/build/Dockerfile b/Dockerfile similarity index 80% rename from build/Dockerfile rename to Dockerfile index a6ade72..3e409b4 100644 --- a/build/Dockerfile +++ b/Dockerfile @@ -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 @@ -14,7 +16,7 @@ RUN adduser \ --home /nonexistent \ --no-create-home \ --gecos "" \ - glche + user WORKDIR /build @@ -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 @@ -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" ] diff --git a/justfile b/justfile index 326ffc7..565152a 100644 --- a/justfile +++ b/justfile @@ -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 @@ -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="": @@ -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 diff --git a/scripts/build.sh b/scripts/build.sh index 98698f3..49a175e 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -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) diff --git a/scripts/dist.sh b/scripts/dist.sh index dd531b5..4f3e553 100755 --- a/scripts/dist.sh +++ b/scripts/dist.sh @@ -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"