Skip to content

Commit

Permalink
Merge actions files for docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
jthoward64 committed Nov 22, 2023
1 parent 0985db6 commit 7cd524b
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 148 deletions.
130 changes: 130 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#
name: Docker build

on:
push:
# Release is a special branch that is kept in sync with the production environment
# We also want to keep the dev environment in sync with the main branch
branches: ['release', 'main']

env:
REGISTRY: ghcr.io
# The name of the image is the name of the repository, with the "-portal" or "-server" suffix (under the UKDanceBlue organization)
PORTAL_IMAGE_NAME: ${{ github.repository }}-portal
SERVER_IMAGE_NAME: ${{ github.repository }}-server

jobs:
build-and-push-portal-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Set up node 18.x
uses: actions/[email protected]
with:
node-version: 18
cache: yarn
- name: Install dependencies
working-directory: ./packages/portal
run: yarn install
- name: Build GraphQL
run: yarn run gql:build
working-directory: .
- name: Build common
run: yarn run build
working-directory: ./packages/common
- name: Build portal
run: yarn run build
working-directory: ./packages/portal
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.SERVER_IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: ./packages/portal
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

build-and-push-server-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Set up node 18.x
uses: actions/[email protected]
with:
node-version: 18
cache: yarn
- name: Install dependencies
working-directory: ./packages/server
run: yarn install
- name: Build common
run: yarn run build
working-directory: ./packages/common
- name: Build server
run: yarn run build
working-directory: ./packages/server
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.PORTAL_IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: ./packages/server/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

trigger-recreate-release:
runs-on: ubuntu-latest
needs: [build-and-push-portal-image, build-and-push-server-image]
if: github.ref == 'refs/heads/release'
steps:
- name: Trigger container recreate
shell: bash
run: |
curl --insecure -X POST ${{ secrets.DANCEBLUE_APP_PORTAL_RECREATE_WEBHOOK }}
trigger-recreate-main:
runs-on: ubuntu-latest
needs: [build-and-push-portal-image, build-and-push-server-image]
if: github.ref == 'refs/heads/main'
steps:
- name: Trigger container recreate
shell: bash
run: |
curl --insecure -X POST ${{ secrets.DANCEBLUE_APP_DEV_PORTAL_RECREATE_WEBHOOK }}
75 changes: 0 additions & 75 deletions .github/workflows/portal.docker-build.yml

This file was deleted.

73 changes: 0 additions & 73 deletions .github/workflows/server.docker-build.yml

This file was deleted.

0 comments on commit 7cd524b

Please sign in to comment.