Skip to content

Commit 74a010b

Browse files
authored
feat: publish BundleMon platform docker image (#223)
1 parent 4d48627 commit 74a010b

27 files changed

+568
-82
lines changed

.github/workflows/build-web.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-22.04
1212
steps:
1313
- uses: actions/checkout@v4
1414
- name: Setup Node.js

.github/workflows/checks.yml

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
packages:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-22.04
1212

1313
strategy:
1414
fail-fast: false
@@ -44,7 +44,10 @@ jobs:
4444
run: yarn lint-packages
4545

4646
website:
47-
runs-on: ubuntu-latest
47+
runs-on: ubuntu-22.04
48+
defaults:
49+
run:
50+
working-directory: ./apps/website
4851

4952
steps:
5053
- uses: actions/checkout@v4
@@ -59,21 +62,21 @@ jobs:
5962
run: yarn
6063

6164
- name: Lint
62-
working-directory: ./apps/website
6365
run: yarn lint
6466

6567
- name: Build
66-
working-directory: ./apps/website
6768
run: yarn build
6869

6970
service:
70-
runs-on: ubuntu-latest
71+
runs-on: ubuntu-22.04
72+
defaults:
73+
run:
74+
working-directory: ./apps/service
7175

7276
steps:
7377
- uses: actions/checkout@v4
7478

7579
- name: Start mock services
76-
working-directory: ./apps/service
7780
run: yarn start:mock-services -d
7881

7982
- name: Setup Node.js
@@ -86,22 +89,61 @@ jobs:
8689
run: yarn
8790

8891
- name: Test
89-
working-directory: ./apps/service
9092
run: yarn test
9193

9294
- uses: codecov/codecov-action@v1
9395
with:
9496
file: ./service/coverage/coverage-final.json
9597

9698
- name: Lint
97-
working-directory: ./apps/service
9899
run: yarn lint
99100

100101
- name: Build
101-
working-directory: ./apps/service
102102
run: yarn build
103103

104104
- name: Stop mock services
105105
if: always()
106-
working-directory: ./apps/service
106+
run: yarn stop:mock-services
107+
108+
platform:
109+
runs-on: ubuntu-22.04
110+
defaults:
111+
run:
112+
working-directory: ./apps/platform
113+
114+
steps:
115+
- uses: actions/checkout@v4
116+
117+
- name: Start mock services
118+
run: yarn start:mock-services -d
119+
120+
- name: Setup Node.js
121+
uses: actions/setup-node@v4
122+
with:
123+
node-version: '18'
124+
cache: 'yarn'
125+
126+
- name: Install dependencies
127+
run: yarn
128+
129+
- name: Build image
130+
env:
131+
INPUT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132+
run: yarn build:image
133+
134+
- name: Start container
135+
run: yarn start:platform
136+
137+
- name: Lint
138+
run: yarn lint
139+
140+
- name: Test
141+
run: yarn test
142+
143+
- name: Stop container
144+
if: always()
145+
run: yarn stop:platform
146+
147+
- name: Stop mock services
148+
if: always()
107149
run: yarn stop:mock-services

.github/workflows/publish-docker.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: publish-docker
2+
3+
on:
4+
push:
5+
tags:
6+
- platform@v*.*.*
7+
8+
concurrency:
9+
group: ${{ github.workflow }}
10+
cancel-in-progress: false
11+
12+
jobs:
13+
publish-docker:
14+
runs-on: ubuntu-22.04
15+
permissions:
16+
contents: read
17+
packages: write
18+
id-token: write # needed for provenance data generation
19+
timeout-minutes: 15
20+
21+
steps:
22+
- name: Login to Github Packages
23+
uses: docker/login-action@v3.3.0
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Extract app name
35+
id: app_name
36+
run: echo "value=$(echo $GITHUB_REF_NAME | cut -d '@' -f 1)" >> $GITHUB_OUTPUT
37+
38+
# validate the version is the same as the tag
39+
- name: Validate version
40+
run: |
41+
ACTUAL_VERSION=$(jq -r '.version' packages/${{ steps.app_name.outputs.value }}/package.json)
42+
EXPECTED_VERSION=$(echo $GITHUB_REF_NAME | sed 's/.*@v//')
43+
if [ "$ACTUAL_VERSION" != "$EXPECTED_VERSION" ]; then
44+
echo "Version mismatch between package.json ($ACTUAL_VERSION) and tag ($EXPECTED_VERSION)"
45+
exit 1
46+
fi
47+
48+
- name: Install Node
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: 20
52+
registry-url: https://registry.npmjs.org/
53+
cache: yarn
54+
55+
- name: Install dependencies
56+
run: yarn
57+
58+
- name: Set up Docker Buildx
59+
uses: docker/setup-buildx-action@v3.8.0
60+
61+
- name: Publish
62+
env:
63+
INPUT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
run: npx nx container ${{ steps.app_name.outputs.value }} --configuration production --verbose

.github/workflows/publish-packages.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
jobs:
1111
test:
1212
name: publish-packages
13-
runs-on: ubuntu-latest
13+
runs-on: ubuntu-22.04
1414
permissions:
1515
contents: read
1616
id-token: write # needed for provenance data generation
@@ -40,6 +40,7 @@ jobs:
4040
with:
4141
node-version: 20
4242
registry-url: https://registry.npmjs.org/
43+
cache: yarn
4344

4445
- name: Install dependencies
4546
run: yarn

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ on:
217217

218218
jobs:
219219
build:
220-
runs-on: ubuntu-latest
220+
runs-on: ubuntu-22.04
221221
steps:
222-
- uses: actions/checkout@v3
222+
- uses: actions/checkout@v4
223223
- name: Setup Node
224-
uses: actions/setup-node@v3
224+
uses: actions/setup-node@v4
225225
with:
226-
node-version: '18'
226+
node-version: '20'
227227

228228
- name: Install dependencies
229229
run: yarn

apps/platform/.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Ignore everything
2+
*
3+
4+
# Allow files and directories
5+
!/dist
6+
7+
# Ignore unnecessary files inside allowed directories
8+
# This should go after the allowed directories
9+
**/.DS_Store

apps/platform/.eslintrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"rules": {
5+
"@typescript-eslint/no-explicit-any": "off"
6+
}
7+
}

apps/platform/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:20-alpine
2+
3+
ENV HOST=0.0.0.0 PORT=3333 SHOULD_SERVE_WEBSITE=true NODE_ENV=production
4+
5+
WORKDIR /app
6+
7+
RUN addgroup --system service && adduser --system -G service service
8+
9+
# Needed by @fastify/secure-session & for source maps
10+
RUN npm i sodium-native@4.2.0 source-map-support@0.5.21
11+
12+
COPY dist service
13+
14+
RUN chown -R service:service .
15+
16+
CMD [ "node", "-r", "source-map-support/register", "service/app.js" ]

apps/platform/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# BundleMon platform
2+
3+
BundleMon platform docker image contains both the service & the website (UI) of BundleMon.

apps/platform/jest.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { Config } from '@jest/types';
2+
3+
export default async (): Promise<Config.InitialOptions> => ({
4+
displayName: 'platform',
5+
preset: '../../jest.preset.js',
6+
});

apps/platform/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "bundlemon-platform",
3+
"version": "1.0.0",
4+
"private": true,
5+
"license": "MIT",
6+
"scripts": {
7+
"build:image": "yarn --cwd ../../ nx container platform --verbose",
8+
"test": "yarn --cwd ../../ nx test platform --verbose",
9+
"lint": "yarn --cwd ../../ nx lint platform --verbose",
10+
"start:mock-services": "docker compose -f ../service/docker-compose.test.yml up --remove-orphans",
11+
"stop:mock-services": "docker compose -f ../service/docker-compose.test.yml down",
12+
"start:platform": "docker run --rm -d --name bundlemon-platform --env-file ../service/.development.env -e NODE_ENV=producation -e MONGO_DB_NAME=test -p 3333:3333 bundlemon-platform",
13+
"stop:platform": "docker stop bundlemon-platform"
14+
},
15+
"dependencies": {},
16+
"devDependencies": {}
17+
}

apps/platform/project.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"name": "platform",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "apps/platform",
5+
"projectType": "application",
6+
"tags": [],
7+
"targets": {
8+
"prepare-image": {
9+
"dependsOn": ["service:build", "website:build"],
10+
"command": "rm -rf apps/platform/dist && cp -r apps/service/dist apps/platform/dist && cp -r dist/apps/website/* apps/platform/dist/public"
11+
},
12+
"container": {
13+
"executor": "@nx-tools/nx-container:build",
14+
"dependsOn": ["prepare-image"],
15+
"defaultConfiguration": "local",
16+
"options": {
17+
"engine": "docker",
18+
"context": "apps/platform",
19+
"file": "apps/platform/Dockerfile",
20+
"metadata": {
21+
"images": ["ghcr.io/lironer/bundlemon-platform"],
22+
"load": true,
23+
"flavor": ["latest=auto"],
24+
"tags": [
25+
"type=semver,pattern={{version}}",
26+
"type=semver,pattern={{major}}.{{minor}}",
27+
"type=semver,pattern=v{{major}}"
28+
],
29+
"cache-from": ["type=registry,ref=ghcr.io/lironer/bundlemon-platform:latest"],
30+
"cache-to": ["type=inline"]
31+
}
32+
},
33+
"configurations": {
34+
"local": {
35+
"metadata": {
36+
"images": ["bundlemon-platform"],
37+
"tags": ["latest"]
38+
},
39+
"push": false
40+
},
41+
"production": {
42+
"platforms": ["linux/amd64", "linux/arm64"],
43+
"provenance": "true",
44+
"push": true
45+
}
46+
}
47+
},
48+
"lint": {
49+
"executor": "@nx/eslint:lint",
50+
"outputs": ["{options.outputFile}"],
51+
"options": {
52+
"lintFilePatterns": ["{projectRoot}/**/*.{ts,js,json}"],
53+
"maxWarnings": 0
54+
}
55+
},
56+
"test": {
57+
"executor": "@nx/jest:jest",
58+
"options": {
59+
"jestConfig": "{projectRoot}/jest.config.ts",
60+
"runInBand": true
61+
}
62+
}
63+
}
64+
}

apps/platform/tests/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const BASE_URL = 'http://localhost:3333';

apps/platform/tests/isAlive.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { BASE_URL } from './consts';
2+
3+
test('is alive', async () => {
4+
const response = await fetch(`${BASE_URL}/is-alive`);
5+
6+
expect(response.status).toEqual(200);
7+
});

apps/platform/tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"module": "ES2022",
5+
"baseUrl": ".",
6+
"paths": {
7+
"@tests/*": ["./tests/*"]
8+
}
9+
},
10+
"references": [
11+
{
12+
"path": "./tsconfig.spec.json"
13+
}
14+
],
15+
"files": [],
16+
"include": []
17+
}

apps/platform/tsconfig.spec.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"types": ["jest", "node"]
6+
},
7+
"include": ["jest.config.ts", "tests/**/*", "scripts/**/*"]
8+
}

apps/service/.development.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ MONGO_DB_NAME=dev
55
MONGO_DB_USER=dev-user
66
MONGO_DB_PASSWORD=password
77
ROOT_DOMAIN=localhost
8-
SECRET_SESSION_KEY="74925e5027a05d9e31082271747a92b11a3b6988fc303bbb2aae330bef92b3a7"
8+
SECRET_SESSION_KEY=74925e5027a05d9e31082271747a92b11a3b6988fc303bbb2aae330bef92b3a7

0 commit comments

Comments
 (0)