add Docker container

This commit is contained in:
Jonas Leder 2023-11-28 15:22:12 +01:00
commit 959227b0af
2 changed files with 45 additions and 2 deletions

View file

@ -26,7 +26,39 @@ build-application-binary:
parallel: !reference [.parallel,parallel]
image: public.ecr.aws/docker/library/golang:1.21.4-bookworm
script:
- go build -o rss2gotify-${GOOS}-${GOARCH} ./
- go build -o gotifyWebhookForwarder-${GOOS}-${GOARCH} ./
artifacts:
paths:
- rss2gotify-${GOOS}-${GOARCH}
- gotifyWebhookForwarder-${GOOS}-${GOARCH}
Docker:
# Use the official docker image.
image: gitlab.jonasled.de/jonasled/buildx-docker:latest
stage: build
needs: []
services:
- docker:dind
before_script:
- docker context create build
- docker buildx create build --use
- docker run --privileged --rm tonistiigi/binfmt --install all
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- apk add jq
# Default branch leaves tagempty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag="latest"
else
tag="$CI_COMMIT_REF_SLUG"
fi
- docker buildx build --platform linux/arm64,linux/amd64 --push --provenance false --tag "$CI_REGISTRY_IMAGE:${tag}" .
- export IMAGE_HASH=$(docker buildx imagetools inspect "$CI_REGISTRY_IMAGE:${tag}" --format "{{json .Manifest}}" | jq .digest)
- "echo \"Image Hash: $IMAGE_HASH\""
- echo "$IMAGE_HASH" >> image-hash.txt
artifacts:
paths:
- image-hash.txt

11
Dockerfile Normal file
View file

@ -0,0 +1,11 @@
FROM public.ecr.aws/docker/library/golang:1.21.4-bookworm AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY *.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -o /gotifyWebhookForwarder
FROM alpine:3.18.4
RUN apk add --no-cache ca-certificates
COPY --from=build /gotifyWebhookForwarder /gotifyWebhookForwarder
ENTRYPOINT ["/gotifyWebhookForwarder"]
EXPOSE 3333