From 58dbc2a5633687554eb853375c97a6b5405cf2e2 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Tue, 24 Oct 2023 07:39:37 -0400 Subject: [PATCH] [add] docker publish --- .drone.yml | 19 +++++++++++++++---- Dockerfile | 11 +++-------- Dockerfile-BuildKit | 32 ++++++++++++++++++++++++++++++++ Makefile | 2 ++ 4 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 Dockerfile-BuildKit diff --git a/.drone.yml b/.drone.yml index e059ffd..cd2ba63 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,15 +3,13 @@ type: kubernetes name: default steps: - - name: generate_tags - image: node - commands: - - echo -n "${DRONE_BRANCH}-$(date +'%Y%m%d%H%M%S')-${DRONE_COMMIT:0:10}, latest" > .tags + # Unit Tests - name: unit test image: golang commands: - make tests_unit + # Integration Tests (Every Month) - name: integration test image: golang commands: @@ -21,3 +19,16 @@ steps: - cron cron: - integration-test + + # Publish Dev Docker Image + - name: publish_docker + image: plugins/docker + settings: + repo: gitea.va.reichard.io/evan/bookmanager + registry: gitea.va.reichard.io + tags: + - dev + username: + from_secret: docker_username + password: + from_secret: docker_password diff --git a/Dockerfile b/Dockerfile index ef7b942..f560ae0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM alpine as certs RUN apk update && apk add ca-certificates # Build Image -FROM --platform=$BUILDPLATFORM golang:1.20 AS build +FROM golang:1.20 AS build # Install Dependencies RUN apt-get update -y @@ -13,13 +13,8 @@ RUN apt install -y gcc-x86-64-linux-gnu WORKDIR /src RUN mkdir -p /opt/bookmanager -# Cache Dependencies & Compile -ARG TARGETOS -ARG TARGETARCH -RUN --mount=target=. \ - --mount=type=cache,target=/root/.cache/go-build \ - --mount=type=cache,target=/go/pkg \ - GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /opt/bookmanager/server; \ +# Compile +RUN go build -o /opt/bookmanager/server; \ cp -a ./templates /opt/bookmanager/templates; \ cp -a ./assets /opt/bookmanager/assets; diff --git a/Dockerfile-BuildKit b/Dockerfile-BuildKit new file mode 100644 index 0000000..ef7b942 --- /dev/null +++ b/Dockerfile-BuildKit @@ -0,0 +1,32 @@ +# Certificate Store +FROM alpine as certs +RUN apk update && apk add ca-certificates + +# Build Image +FROM --platform=$BUILDPLATFORM golang:1.20 AS build + +# Install Dependencies +RUN apt-get update -y +RUN apt install -y gcc-x86-64-linux-gnu + +# Create Package Directory +WORKDIR /src +RUN mkdir -p /opt/bookmanager + +# Cache Dependencies & Compile +ARG TARGETOS +ARG TARGETARCH +RUN --mount=target=. \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg \ + GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /opt/bookmanager/server; \ + cp -a ./templates /opt/bookmanager/templates; \ + cp -a ./assets /opt/bookmanager/assets; + +# Create Image +FROM busybox:1.36 +COPY --from=certs /etc/ssl/certs /etc/ssl/certs +COPY --from=build /opt/bookmanager /opt/bookmanager +WORKDIR /opt/bookmanager +EXPOSE 8585 +ENTRYPOINT ["/opt/bookmanager/server", "serve"] diff --git a/Makefile b/Makefile index dedcc08..1ca0baa 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ docker_build_release_dev: docker buildx build \ --platform linux/amd64,linux/arm64 \ -t gitea.va.reichard.io/evan/bookmanager:dev \ + -f Dockerfile-BuildKit \ --push . docker_build_release_latest: @@ -24,6 +25,7 @@ docker_build_release_latest: --platform linux/amd64,linux/arm64 \ -t gitea.va.reichard.io/evan/bookmanager:latest \ -t gitea.va.reichard.io/evan/bookmanager:`git describe --tags` \ + -f Dockerfile-BuildKit \ --push . tests_integration: