Skip to content

Commit

Permalink
deploy with dockerhub
Browse files Browse the repository at this point in the history
  • Loading branch information
ganiszulfa committed Dec 18, 2022
1 parent bf90b1b commit 2c89b9d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
31 changes: 22 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@

name: Go

env:
CONTEXT_DIR: './'
IMAGE_NAME: ${{ github.repository }}/backend
DOCKERFILE: backend.Dockerfile
CAPROVER_APP: concise
DOCKER_REGISTRY: ghcr.io

on:
push:
tags:
- 'bv[0-9]+.[0-9]+.[0-9]+'

jobs:

build:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
echo "IMAGE_NAME_WITH_REGISTRY=$DOCKER_REGISTRY/$IMAGE_NAME" >> $GITHUB_ENV
export IMAGE_NAME_WITH_REGISTRY=$DOCKER_REGISTRY/$IMAGE_NAME
echo "FULL_IMAGE_NAME=$IMAGE_NAME_WITH_REGISTRY:$GITHUB_SHA-gitsha" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v3
Expand All @@ -27,20 +38,22 @@ jobs:
go build -v ./...
go test -v ./...
- uses: a7ul/tar-action@v1.1.0
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
command: c
cwd: "./"
files: |
./backend
./backend/captain-definition
./backend/Dockerfile
outPath: deploy.tar
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push Release to DockerHub
shell: bash
run: ./build_and_push.sh

- name: Deploy App to CapRover
uses: caprover/deploy-from-github@v1.0.1
with:
server: '${{ secrets.CAPROVER_SERVER }}'
app: '${{ secrets.APP_NAME }}'
token: '${{ secrets.APP_TOKEN }}'
image: '${{ env.FULL_IMAGE_NAME }}'

6 changes: 3 additions & 3 deletions backend/Dockerfile → backend.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ FROM golang:1.19-alpine
# install dependencies
RUN mkdir -p /app
WORKDIR /app
COPY ./go.mod /app
COPY ./go.sum /app
COPY ./backend/go.mod /app
COPY ./backend/go.sum /app
RUN go mod download

# Copy all local files into the image.
COPY ./ /app
COPY ./backend /app

RUN go build -o /backend

Expand Down
14 changes: 14 additions & 0 deletions build_and_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

cd $CONTEXT_DIR
rm /tmp/build_args || echo OK
env >/tmp/build_args
echo "--build-arg \""$(cat /tmp/build_args | sed -z 's/\n/" --build-arg "/g')"IGNORE_VAR=IGNORE_VAR\"" >/tmp/build_args
BUILD_ARGS=$(cat /tmp/build_args)
COMMAND="docker build -t $FULL_IMAGE_NAME -t $IMAGE_NAME_WITH_REGISTRY:latest -f $DOCKERFILE $BUILD_ARGS --no-cache ."
/bin/bash -c "$COMMAND"
docker push $IMAGE_NAME_WITH_REGISTRY:latest
docker push $FULL_IMAGE_NAME
rm /tmp/build_args

0 comments on commit 2c89b9d

Please sign in to comment.