Skip to content

Merge pull request #601 from CodeForAfrica/chore/ui_update #189

Merge pull request #601 from CodeForAfrica/chore/ui_update

Merge pull request #601 from CodeForAfrica/chore/ui_update #189

name: Code for Africa | Deploy | PROD
on:
push:
branches: [main]
# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: "${{ github.workflow }} @ ${{ github.ref }}"
cancel-in-progress: true
env:
DOKKU_REMOTE_BRANCH: "master"
DOKKU_REMOTE_URL: "ssh://[email protected]/codeforafrica-ui"
IMAGE_NAME: "codeforafrica/codeforafrica-ui"
APP: "codeforafrica"
VERSION_FILE_NAME: "./apps/codeforafrica/package.json"
GIT_PUSH_FLAGS: "--force"
jobs:
deploy:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [18]
os: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# Set up Node since it's required by version-check
# https://github.com/EndBug/version-check#github-workflow
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Check if version is bumped
id: version-check
uses: EndBug/version-check@v2
with:
# Whether to search in every commit's diff.
# This is useful if you often do change the version without saying it
# in the commit message. If you always include the semver of the new
# version in your commit message when you bump versions then you can
# omit this.
diff-search: true
file-name: "${{ env.VERSION_FILE_NAME }}"
- name: Set up Docker Buildx
if: steps.version-check.outputs.changed == 'true'
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
if: steps.version-check.outputs.changed == 'true'
uses: actions/cache@v3
with:
key: ${{ runner.os }}-buildx-${{ github.sha }}
path: /tmp/.buildx-cache
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
if: steps.version-check.outputs.changed == 'true'
uses: docker/login-action@v2
with:
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
username: ${{ secrets.DOCKER_HUB_USERNAME }}
- name: Build Docker image
if: steps.version-check.outputs.changed == 'true'
uses: docker/build-push-action@v3
with:
build-args: |
APP=${{ env.APP }}
GHOST_API_KEY=${{ secrets.GHOST_API_KEY }}
GOOGLE_API_KEY=${{ secrets.GOOGLE_API_KEY }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
context: .
push: true
tags: "${{ env.IMAGE_NAME }}:${{ steps.version-check.outputs.version }}"
- name: Move cache
if: steps.version-check.outputs.changed == 'true'
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Push to Dokku
if: steps.version-check.outputs.changed == 'true'
uses: dokku/[email protected]
with:
branch: ${{ env.DOKKU_REMOTE_BRANCH }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
git_push_flags: ${{ env.GIT_PUSH_FLAGS }}
git_remote_url: ${{ env.DOKKU_REMOTE_URL }}