Containerize application and configure GitHub Actions to build and push Docker image to Harbor #1940
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI Build | |
on: | |
pull_request: | |
# By default, the pull_request event type is not triggered when a PR is merged into main or develop | |
push: | |
branches: | |
- main | |
- develop | |
jobs: | |
test: | |
name: Tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3 | |
with: | |
node-version: 20 | |
cache: 'yarn' | |
- name: Install dependencies | |
# Ubuntu 16+ does not install libgconf-2-4 by default, so we need to install it ourselves (for Cypress) | |
run: | | |
sudo apt-get install libgconf-2-4 | |
yarn --immutable | |
- name: Run linting | |
run: yarn lint:js | |
- name: Run unit tests | |
run: yarn test | |
- name: Upload unit test coverage | |
if: success() | |
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3 | |
- name: Run e2e tests | |
run: yarn e2e | |
docker: | |
# This job triggers only if all the other jobs succeed and does different things depending on the context. | |
# The job builds the Docker image in all cases and also pushes the image to Harbor only if something is | |
# pushed to the main or develop branch. | |
needs: [test] | |
name: Docker | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3 | |
- name: Login to Harbor | |
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0 | |
with: | |
registry: harbor.stfc.ac.uk/datagateway | |
username: ${{ secrets.HARBOR_USERNAME }} | |
password: ${{ secrets.HARBOR_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@c4ee3adeed93b1fa6a762f209fb01608c1a22f1e # v4.4.0 | |
with: | |
images: harbor.stfc.ac.uk/datagateway/scigateway | |
- name: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') && 'Build and push Docker image to Harbor' || 'Build Docker image' }} | |
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0 | |
with: | |
context: . | |
push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |