Make sure container is able to start up (#23)
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/22
This commit is contained in:
parent
780600e3dd
commit
bd5c14242e
|
@ -73,3 +73,24 @@ jobs:
|
||||||
file: 'Dockerfile'
|
file: 'Dockerfile'
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
||||||
|
# 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-public-archive:
|
||||||
|
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
|
||||||
|
|
|
@ -6,12 +6,16 @@ WORKDIR /app
|
||||||
|
|
||||||
RUN npm install npm@^8 --location=global
|
RUN npm install npm@^8 --location=global
|
||||||
|
|
||||||
|
# Copy the health-check script
|
||||||
|
COPY docker-health-check.js /app/
|
||||||
|
|
||||||
# Copy just what we need to install the dependencies so this layer can be cached
|
# Copy just what we need to install the dependencies so this layer can be cached
|
||||||
# in the Docker build
|
# in the Docker build
|
||||||
COPY package.json package-lock.json /app/
|
COPY package.json package-lock.json /app/
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
# Copy what we need for the client-side build
|
# Copy what we need for the client-side build
|
||||||
|
COPY config /app/config/
|
||||||
COPY public /app/public/
|
COPY public /app/public/
|
||||||
COPY shared /app/shared/
|
COPY shared /app/shared/
|
||||||
COPY vite.config.js /app/
|
COPY vite.config.js /app/
|
||||||
|
@ -21,4 +25,6 @@ RUN npm run build
|
||||||
# Copy the rest of the app
|
# Copy the rest of the app
|
||||||
COPY server /app/server/
|
COPY server /app/server/
|
||||||
|
|
||||||
ENTRYPOINT ["npm" "start"]
|
HEALTHCHECK CMD node docker-health-check.js
|
||||||
|
|
||||||
|
ENTRYPOINT ["/bin/bash", "-c", "npm start"]
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const { fetchEndpointAsJson } = require('./server/lib/fetch-endpoint');
|
||||||
|
|
||||||
|
const config = require('./server/lib/config');
|
||||||
|
const basePort = config.get('basePort');
|
||||||
|
assert(basePort);
|
||||||
|
|
||||||
|
const healthCheckUrl = `http://localhost:${basePort}/health-check`;
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
await fetchEndpointAsJson(healthCheckUrl);
|
||||||
|
process.exit(0);
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`Health check error: ${healthCheckUrl}`, err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
})();
|
|
@ -48,15 +48,15 @@ async function fetchEndpointAsText(endpoint, options) {
|
||||||
|
|
||||||
async function fetchEndpointAsJson(endpoint, options) {
|
async function fetchEndpointAsJson(endpoint, options) {
|
||||||
const opts = {
|
const opts = {
|
||||||
...options,
|
...(options || {}),
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
...(options.headers || {}),
|
...(options?.headers || {}),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.body) {
|
if (options?.body) {
|
||||||
opts.body = JSON.stringify(options.body);
|
opts.body = JSON.stringify(options.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,10 @@ function parseArchiveRangeFromReq(req) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function installRoutes(app) {
|
function installRoutes(app) {
|
||||||
|
app.get('/health-check', async function (req, res) {
|
||||||
|
res.send('{ "ok": true }');
|
||||||
|
});
|
||||||
|
|
||||||
// We have to disable no-missing-require lint because it doesn't take into
|
// We have to disable no-missing-require lint because it doesn't take into
|
||||||
// account `package.json`. `exports`, see
|
// account `package.json`. `exports`, see
|
||||||
// https://github.com/mysticatea/eslint-plugin-node/issues/255
|
// https://github.com/mysticatea/eslint-plugin-node/issues/255
|
||||||
|
|
Loading…
Reference in New Issue