From 2d9a8f2597fb3caf9367cd512f43d197fbea2456 Mon Sep 17 00:00:00 2001 From: Scotow Date: Sun, 22 Dec 2019 00:14:49 +0100 Subject: [PATCH] Update Dockerfile and CI/CD --- .github/workflows/docker.yml | 46 ++++++++++++++++++++++++++++++++++++ cmd/web/Dockerfile | 23 +++++++++++------- 2 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..743b962 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,46 @@ +name: Docker + +on: + release: + types: [published] + +jobs: + publish-web: + runs-on: ubuntu-latest + steps: + - name: Pulling repo + uses: actions/checkout@v1 + - name: Building latest image + run: docker build -f cmd/web/Dockerfile -t image:latest . + - name: Adding additional tags + run: | + REPO=$(cut -d/ -f2 <<< $GITHUB_REPOSITORY) + VERSION=$(rev <<< $GITHUB_REF | cut -d/ -f1 | rev | tr -d v) + docker tag image:latest docker.pkg.github.com/$GITHUB_REPOSITORY/$REPO-web:latest + docker tag image:latest docker.pkg.github.com/$GITHUB_REPOSITORY/$REPO-web:$GITHUB_SHA + docker tag image:latest docker.pkg.github.com/$GITHUB_REPOSITORY/$REPO-web:$VERSION + - name: Loging in + run: | + USER=$(cut -d/ -f1 <<< $GITHUB_REPOSITORY) + docker login docker.pkg.github.com -u $USER -p ${{ secrets.GITHUB_TOKEN }} + - name: Pushing image + run: | + REPO=$(cut -d/ -f2 <<< $GITHUB_REPOSITORY) + VERSION=$(rev <<< $GITHUB_REF | cut -d/ -f1 | rev | tr -d v) + docker push docker.pkg.github.com/$GITHUB_REPOSITORY/$REPO-web:latest + docker push docker.pkg.github.com/$GITHUB_REPOSITORY/$REPO-web:$GITHUB_SHA + docker push docker.pkg.github.com/$GITHUB_REPOSITORY/$REPO-web:$VERSION + - name: Writing stack config file + run: | + VERSION=$(rev <<< $GITHUB_REF | cut -d/ -f1 | rev | tr -d v) + echo '${{ secrets.DOCKER_STACK_YAML }}' > stack.yaml + sed -i "s/latest/$VERSION/g" stack.yaml + - name: Deploying new version + uses: scotow/docker-ssh-action@v2 + with: + remote_host: ${{ secrets.REMOTE_HOST }} + remote_user: ${{ secrets.REMOTE_USER }} + remote_ssh_public_key: ${{ secrets.REMOTE_SSH_PUBLIC_KEY }} + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + github_token: ${{ secrets.GITHUB_TOKEN }} + args: stack deploy -c stack.yaml --with-registry-auth burgoking \ No newline at end of file diff --git a/cmd/web/Dockerfile b/cmd/web/Dockerfile index 7e79a4b..e695f85 100644 --- a/cmd/web/Dockerfile +++ b/cmd/web/Dockerfile @@ -1,13 +1,15 @@ -################################ -# STEP 1 build executable binary -################################ +################################## +# STEP 1 build executable binary # +################################## FROM golang:alpine AS builder # Install git. # Git is required for fetching the dependencies. RUN apk update && apk add --no-cache git -WORKDIR $GOPATH/src/scotow/burgoking/cmd/web -COPY . . +COPY . $GOPATH/src/github.com/scotow/burgoking + +# Move to command directory. +WORKDIR $GOPATH/src/github.com/scotow/burgoking/cmd/web # Fetch dependencies. # Using go get. @@ -16,18 +18,21 @@ RUN go get -d -v # Build the binary. RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/burgoking -############################ -# STEP 2 build a small image -############################ +############################## +# STEP 2 build a small image # +############################## FROM scratch # Copy our static executable and static files. COPY --from=builder /go/bin/burgoking /burgoking -COPY static /static +COPY cmd/web/static /static # Copy SSL certificates for HTTPS connections. COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +# Copy locale data. +COPY --from=builder /usr/local/go/lib/time/zoneinfo.zip / +ENV ZONEINFO=/zoneinfo.zip # Run the hello binary. ENTRYPOINT ["/burgoking"] \ No newline at end of file