-
Notifications
You must be signed in to change notification settings - Fork 11
97 lines (85 loc) · 3.38 KB
/
containerize.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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