matrix-public-archive/.github/workflows/containerize.yaml

98 lines
3.4 KiB
YAML

name: Containerize
on:
push:
branches: [main]
env:
REGISTRY: ghcr.io
GHCR_NAMESPACE: matrix-org/matrix-viewer
IMAGE_NAME: matrix-viewer
jobs:
# Create and publish a Docker image for matrix-viewer
#
# Based off of
# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages
build-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
# Make the Docker image name available to use in other jobs as `${{
# needs.build-image.outputs.docker_image_name }}`. Also see
# the `save_var` step below for how this works.
docker_image_name: ${{ steps.save_var.outputs.docker_image_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the GitHub Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Trick to get env variables available in `needs` context which is
# available to use in almost everywhere
# (https://docs.github.com/en/actions/learn-github-actions/contexts). This
# is so that we can reference the same Docker image name in the `services` of
# the next job.
#
# via https://github.community/t/how-to-use-env-with-container-image/17252/25
- name: Save the Docker image name to a variable so we can share and re-use it in other jobs via `${{ needs.build-image.outputs.docker_image_name }}`
id: save_var
run: echo "::set-output name=docker_image_name::${{ env.REGISTRY }}/${{ env.GHCR_NAMESPACE }}/${{ env.IMAGE_NAME }}"
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ steps.save_var.outputs.docker_image_name }}
# Defaults (as indicated by https://github.com/docker/metadata-action/tree/97c170d70b5f8bfc77e6b23e68381f217cb64ded#tags-input).
# Plus custom tags:
# - Full length sha
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha,format=long
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
push: true
context: '.'
file: 'Dockerfile'
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GITHUB_SHA=${{ github.sha }}
GITHUB_REF=${{ github.ref_name }}
# Just make sure the container can start-up and responds to the health check
test-image:
needs: [build-image]
runs-on: ubuntu-latest
services:
matrix-viewer:
image: ${{ needs.build-image.outputs.docker_image_name }}:sha-${{ github.sha }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
ports:
- 3050:3050
env:
matrixServerUrl: http://FAKE_SERVER/
matrixAccessToken: FAKE_TOKEN
steps:
- name: See if the container will respond to a request
run: curl http://localhost:3050/health-check