Attempt to pin to run-specific image #212
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: Build | |
on: [ push, workflow_dispatch ] | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
build_url: ${{ steps.data.outputs.build_url }} | |
steps: | |
- id: data | |
name: Populates outputs | |
run: | | |
echo "build_url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" >> "$GITHUB_OUTPUT" | |
test: | |
if: github.event_name != 'release' | |
needs: setup | |
env: | |
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml | |
DOCKER_APP_IMAGE: app-run-${{ github.run_id}} | |
outputs: | |
imageid: ${{ steps.image }} | |
permissions: | |
packages: write | |
contents: read | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: true | |
matrix: | |
os_family: | |
- linux | |
architecture: | |
- amd64 | |
- arm64 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- id: meta | |
name: Construct image tags and labels | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/berkeleylibrary/geodata | |
labels: | | |
edu.berkeley.lib.build-timestamp=${{ github.event.repository.updated_at }} | |
edu.berkeley.lib.build-url=${{ needs.setup.outputs.build_url }} | |
edu.berkeley.lib.git-ref-name=${{ github.ref_name }} | |
edu.berkeley.lib.git-repository-url=${{ github.repositoryUrl }} | |
edu.berkeley.lib.git-sha=${{ github.sha }} | |
tags: | | |
type=raw,value=${{ env.DOCKER_APP_IMAGE }} | |
type=sha | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
- id: image | |
name: Build the docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
build-args: | | |
BUILD_TIMESTAMP=${{ github.event.repository.updated_at }} | |
BUILD_URL=${{ needs.setup.outputs.build_url }} | |
GIT_REF_NAME=${{ github.ref_name }} | |
GIT_REPOSITORY_URL=${{ github.repositoryUrl }} | |
GIT_SHA=${{ github.sha }} | |
platforms: ${{ matrix.os_family }}/${{ matrix.architecture }} | |
push: false | |
labels: ${{ steps.meta.outputs.labels }} | |
tags: ${{ steps.meta.outputs.tags }} | |
- name: Start the stack | |
run: | | |
docker compose up --build --detach | |
sleep 10 | |
- name: Run RSpec tests | |
run: | | |
docker compose exec -e RAILS_ENV=test app rake | |
- name: Extract service logs | |
if: ${{ always() }} | |
run: | | |
mkdir -p tmp/artifacts | |
docker compose logs > tmp/artifacts/docker-compose.log | |
docker compose cp app:/opt/app/artifacts/ tmp/ | |
- name: Upload testing artifacts | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-results-${{ matrix.os_family }}-${{ matrix.architecture }} | |
path: tmp/artifacts |