Containerize app (make a Docker image for `matrix-public-archive`) (#22)
Containerize app (make a Docker image for `matrix-public-archive`) ``` ghcr.io/matrix-org/matrix-public-archive/matrix-public-archive ``` ... with a variety of tags! Packages viewable on https://github.com/matrix-org/matrix-public-archive/pkgs/container/matrix-public-archive%2Fmatrix-public-archive
This commit is contained in:
parent
3e85ae3b60
commit
780600e3dd
|
@ -0,0 +1,75 @@
|
||||||
|
name: Containerize
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
GHCR_NAMESPACE: matrix-org/matrix-public-archive
|
||||||
|
IMAGE_NAME: matrix-public-archive
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# Create and publish a Docker image for matrix-public-archive
|
||||||
|
#
|
||||||
|
# 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 }}
|
|
@ -17,7 +17,7 @@ jobs:
|
||||||
#
|
#
|
||||||
# Based off of
|
# Based off of
|
||||||
# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages
|
# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages
|
||||||
deploy-test-synapse-image:
|
build-test-synapse-image:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
@ -25,7 +25,7 @@ jobs:
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
# Make the Docker image name available to use in other jobs as `${{
|
# Make the Docker image name available to use in other jobs as `${{
|
||||||
# needs.deploy-test-synapse-image.outputs.docker_image_name }}`. Also see
|
# needs.build-test-synapse-image.outputs.docker_image_name }}`. Also see
|
||||||
# the `save_var` step below for how this works.
|
# the `save_var` step below for how this works.
|
||||||
docker_image_name: ${{ steps.save_var.outputs.docker_image_name }}
|
docker_image_name: ${{ steps.save_var.outputs.docker_image_name }}
|
||||||
|
|
||||||
|
@ -47,21 +47,36 @@ jobs:
|
||||||
# the next job.
|
# the next job.
|
||||||
#
|
#
|
||||||
# via https://github.community/t/how-to-use-env-with-container-image/17252/25
|
# 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.deploy-test-synapse-image.outputs.docker_image_name }}`
|
- name: Save the Docker image name to a variable so we can share and re-use it in other jobs via `${{ needs.build-test-synapse-image.outputs.docker_image_name }}`
|
||||||
id: save_var
|
id: save_var
|
||||||
run: echo "::set-output name=docker_image_name::${{ env.REGISTRY }}/${{ env.GHCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
|
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
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
|
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
|
||||||
${{ steps.save_var.outputs.docker_image_name }}
|
|
||||||
context: test/dockerfiles/
|
context: test/dockerfiles/
|
||||||
file: 'test/dockerfiles/Synapse.Dockerfile'
|
file: 'test/dockerfiles/Synapse.Dockerfile'
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
||||||
tests:
|
tests:
|
||||||
needs: [deploy-test-synapse-image]
|
needs: [build-test-synapse-image]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -71,7 +86,7 @@ jobs:
|
||||||
services:
|
services:
|
||||||
# We need two homeservers that federate with each other to test with
|
# We need two homeservers that federate with each other to test with
|
||||||
hs1:
|
hs1:
|
||||||
image: ${{ needs.deploy-test-synapse-image.outputs.docker_image_name }}
|
image: ${{ needs.build-test-synapse-image.outputs.docker_image_name }}:sha-${{ github.sha }}
|
||||||
credentials:
|
credentials:
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
@ -80,7 +95,7 @@ jobs:
|
||||||
env:
|
env:
|
||||||
SERVER_NAME: hs1
|
SERVER_NAME: hs1
|
||||||
hs2:
|
hs2:
|
||||||
image: ${{ needs.deploy-test-synapse-image.outputs.docker_image_name }}
|
image: ${{ needs.build-test-synapse-image.outputs.docker_image_name }}:sha-${{ github.sha }}
|
||||||
credentials:
|
credentials:
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
FROM node:16.15-buster-slim
|
||||||
|
|
||||||
|
RUN mkdir -p /app
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN npm install npm@^8 --location=global
|
||||||
|
|
||||||
|
# Copy just what we need to install the dependencies so this layer can be cached
|
||||||
|
# in the Docker build
|
||||||
|
COPY package.json package-lock.json /app/
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# Copy what we need for the client-side build
|
||||||
|
COPY public /app/public/
|
||||||
|
COPY shared /app/shared/
|
||||||
|
COPY vite.config.js /app/
|
||||||
|
# Build the client-side bundle
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Copy the rest of the app
|
||||||
|
COPY server /app/server/
|
||||||
|
|
||||||
|
ENTRYPOINT ["npm" "start"]
|
|
@ -2,9 +2,10 @@
|
||||||
"name": "matrix-public-archive",
|
"name": "matrix-public-archive",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start-dev": "node server/start-dev.js",
|
|
||||||
"lint": "eslint **/*.js",
|
"lint": "eslint **/*.js",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
|
"start": "node server/server.js",
|
||||||
|
"start-dev": "node server/start-dev.js",
|
||||||
"test": "npm run mocha -- test/e2e-tests.js --timeout 15000",
|
"test": "npm run mocha -- test/e2e-tests.js --timeout 15000",
|
||||||
"test-interactive": "npm run mocha -- test/e2e-tests.js --timeout 15000 --interactive",
|
"test-interactive": "npm run mocha -- test/e2e-tests.js --timeout 15000 --interactive",
|
||||||
"nodemon": "nodemon",
|
"nodemon": "nodemon",
|
||||||
|
|
|
@ -17,6 +17,11 @@ handlers:
|
||||||
# log to stdout, for easier use with 'docker logs'
|
# log to stdout, for easier use with 'docker logs'
|
||||||
stream: 'ext://sys.stdout'
|
stream: 'ext://sys.stdout'
|
||||||
|
|
||||||
|
|
||||||
|
# loggers:
|
||||||
|
# synapse.rest.media.v1.thumbnail_resource:
|
||||||
|
# level: DEBUG
|
||||||
|
|
||||||
root:
|
root:
|
||||||
level: INFO
|
level: INFO
|
||||||
handlers: [console]
|
handlers: [console]
|
||||||
|
|
Loading…
Reference in New Issue