Skip to content

Commit

Permalink
Update Dockerfile and CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
scotow committed Dec 21, 2019
1 parent fd78f27 commit 2d9a8f2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 14 additions & 9 deletions cmd/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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"]

0 comments on commit 2d9a8f2

Please sign in to comment.