Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Make ccache check safer #67

Make ccache check safer

Make ccache check safer #67

name: Build
on:
pull_request:
branches:
- 'v1-stable'
- 'main'
jobs:
# Check
check:
name: Ensure Latest
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check if branch is ahead of v1-stable
run: |
if ! git merge-base --is-ancestor origin/v1-stable ${{ github.event.pull_request.head.sha }};
then echo "This branch is not up to date with v1-stable. Skipping build to save resources.";
exit 1; fi
# Backend
# Build the backend first, which includes the frontend layers at the beginning. We then build the frontend which will
# immediately build from the cache in the backend layers but without the bloat of the backend layers.
build:
name: Build
needs: check
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log into registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/amrc-factoryplus/acs-manager
- name: Check Backend Builder
id: check-backend-builder
run: |
docker manifest inspect ghcr.io/amrc-factoryplus/acs-manager:backend-build-1.0.0 || echo "needs-build=true" >> $GITHUB_OUTPUT
- name: Build Backend Builder
id: build-backend-builder
if: steps.check-backend-builder.outputs.needs-build == 'true'
uses: docker/build-push-action@v4
with:
context: .
file: ./.docker/Dockerfiles/Dockerfile.backend-build
push: true
tags: ghcr.io/amrc-factoryplus/acs-manager:backend-build-1.0.0
- name: Check Backend Base
id: check-backend-base
run: |
docker manifest inspect ghcr.io/amrc-factoryplus/acs-manager:prod-base-php82-1.0.6 || echo "needs-build=true" >> $GITHUB_OUTPUT
- name: Build Backend Base
id: build-backend-base
if: steps.check-backend-base.outputs.needs-build == 'true'
uses: docker/build-push-action@v4
with:
context: .
file: ./.docker/Dockerfiles/Dockerfile.backend-base
push: true
tags: ghcr.io/amrc-factoryplus/acs-manager:prod-base-php82-1.0.6
- name: Build Backend
id: build-backend
uses: docker/build-push-action@v4
with:
context: .
file: ./.docker/Dockerfiles/Dockerfile
load: true
tags: ${{ steps.meta.outputs.tags }}-backend
labels: ${{ steps.meta.outputs.labels }}
outputs: type=docker,dest=/tmp/image.tar
- name: Upload Backend
uses: actions/upload-artifact@v2
with:
name: ${{ github.event.number }}
path: /tmp/image.tar
- name: Build & Push Frontend
id: build-and-push-frontend
uses: docker/build-push-action@v4
with:
context: .
push: true
file: ./.docker/Dockerfiles/Dockerfile
target: production-frontend
tags: ${{ steps.meta.outputs.tags }}-frontend
labels: ${{ steps.meta.outputs.labels }}
push-backend:
name: Push Backend
runs-on: ubuntu-latest
needs: build
permissions:
contents: read
packages: write
id-token: write
pull-requests: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/amrc-factoryplus/acs-manager
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ github.event.number }}
path: /tmp
- name: Load and push image
run: |
docker load --input /tmp/image.tar
docker image ls -a
docker push ${{ steps.meta.outputs.tags }}-backend