From 2cb34eb4778570915c4d6d619df23263194e92c0 Mon Sep 17 00:00:00 2001 From: Felix Auringer <48409110+felixauringer@users.noreply.github.com> Date: Mon, 26 Apr 2021 15:36:24 +0200 Subject: [PATCH] Add CI job building the binary and a docker image --- .gitlab-ci.yml | 34 ++++++++++++++++++++++++++++++++++ Dockerfile | 8 ++++++++ 2 files changed, 42 insertions(+) create mode 100644 Dockerfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0027949..81e3bfd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,8 +2,26 @@ default: image: golang:latest stages: + - build - lint - test + - docker + +variables: + DOCKER_TLS_CERTDIR: "" + IMAGE_NAME: $DOCKER_REGISTRY/$DOCKER_IMAGE_NAME/$CI_COMMIT_REF_SLUG:latest + +compile: + stage: build + needs: [] + variables: + CGO_ENABLED: 0 + script: + - go build -o poseidon + artifacts: + paths: + - poseidon + expire_in: 1 week golangci-lint: stage: lint @@ -24,3 +42,19 @@ test: needs: [] script: - go test ./... -v + +dockerimage: + stage: docker + image: docker:latest + services: + - name: docker:dind + alias: docker + needs: + - compile + script: + - docker login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_PASSWORD $DOCKER_REGISTRY + # Prevent pull rate limit but still have normal alpine image in Dockerfile + - docker pull $DOCKER_REGISTRY/library/alpine:latest + - docker tag $DOCKER_REGISTRY/library/alpine:latest alpine:latest + - docker build -t $IMAGE_NAME . + - docker push $IMAGE_NAME diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..75b0eec --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM alpine:latest + +RUN adduser --disabled-password api +USER api +COPY poseidon /home/api/ + +EXPOSE 3000 +CMD ["/home/api/poseidon"]