-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: publish BundleMon platform docker image (#223)
- Loading branch information
Showing
27 changed files
with
568 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: publish-docker | ||
|
||
on: | ||
push: | ||
tags: | ||
- platform@v*.*.* | ||
|
||
concurrency: | ||
group: ${{ github.workflow }} | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
publish-docker: | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write # needed for provenance data generation | ||
timeout-minutes: 15 | ||
|
||
steps: | ||
- name: Login to Github Packages | ||
uses: docker/[email protected] | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Extract app name | ||
id: app_name | ||
run: echo "value=$(echo $GITHUB_REF_NAME | cut -d '@' -f 1)" >> $GITHUB_OUTPUT | ||
|
||
# validate the version is the same as the tag | ||
- name: Validate version | ||
run: | | ||
ACTUAL_VERSION=$(jq -r '.version' packages/${{ steps.app_name.outputs.value }}/package.json) | ||
EXPECTED_VERSION=$(echo $GITHUB_REF_NAME | sed 's/.*@v//') | ||
if [ "$ACTUAL_VERSION" != "$EXPECTED_VERSION" ]; then | ||
echo "Version mismatch between package.json ($ACTUAL_VERSION) and tag ($EXPECTED_VERSION)" | ||
exit 1 | ||
fi | ||
- name: Install Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
registry-url: https://registry.npmjs.org/ | ||
cache: yarn | ||
|
||
- name: Install dependencies | ||
run: yarn | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/[email protected] | ||
|
||
- name: Publish | ||
env: | ||
INPUT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: npx nx container ${{ steps.app_name.outputs.value }} --configuration production --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Ignore everything | ||
* | ||
|
||
# Allow files and directories | ||
!/dist | ||
|
||
# Ignore unnecessary files inside allowed directories | ||
# This should go after the allowed directories | ||
**/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM node:20-alpine | ||
|
||
ENV HOST=0.0.0.0 PORT=3333 SHOULD_SERVE_WEBSITE=true NODE_ENV=production | ||
|
||
WORKDIR /app | ||
|
||
RUN addgroup --system service && adduser --system -G service service | ||
|
||
# Needed by @fastify/secure-session & for source maps | ||
RUN npm i [email protected] [email protected] | ||
|
||
COPY dist service | ||
|
||
RUN chown -R service:service . | ||
|
||
CMD [ "node", "-r", "source-map-support/register", "service/app.js" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# BundleMon platform | ||
|
||
BundleMon platform docker image contains both the service & the website (UI) of BundleMon. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { Config } from '@jest/types'; | ||
|
||
export default async (): Promise<Config.InitialOptions> => ({ | ||
displayName: 'platform', | ||
preset: '../../jest.preset.js', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "bundlemon-platform", | ||
"version": "1.0.0", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"build:image": "yarn --cwd ../../ nx container platform --verbose", | ||
"test": "yarn --cwd ../../ nx test platform --verbose", | ||
"lint": "yarn --cwd ../../ nx lint platform --verbose", | ||
"start:mock-services": "docker compose -f ../service/docker-compose.test.yml up --remove-orphans", | ||
"stop:mock-services": "docker compose -f ../service/docker-compose.test.yml down", | ||
"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", | ||
"stop:platform": "docker stop bundlemon-platform" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"name": "platform", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "apps/platform", | ||
"projectType": "application", | ||
"tags": [], | ||
"targets": { | ||
"prepare-image": { | ||
"dependsOn": ["service:build", "website:build"], | ||
"command": "rm -rf apps/platform/dist && cp -r apps/service/dist apps/platform/dist && cp -r dist/apps/website/* apps/platform/dist/public" | ||
}, | ||
"container": { | ||
"executor": "@nx-tools/nx-container:build", | ||
"dependsOn": ["prepare-image"], | ||
"defaultConfiguration": "local", | ||
"options": { | ||
"engine": "docker", | ||
"context": "apps/platform", | ||
"file": "apps/platform/Dockerfile", | ||
"metadata": { | ||
"images": ["ghcr.io/lironer/bundlemon-platform"], | ||
"load": true, | ||
"flavor": ["latest=auto"], | ||
"tags": [ | ||
"type=semver,pattern={{version}}", | ||
"type=semver,pattern={{major}}.{{minor}}", | ||
"type=semver,pattern=v{{major}}" | ||
], | ||
"cache-from": ["type=registry,ref=ghcr.io/lironer/bundlemon-platform:latest"], | ||
"cache-to": ["type=inline"] | ||
} | ||
}, | ||
"configurations": { | ||
"local": { | ||
"metadata": { | ||
"images": ["bundlemon-platform"], | ||
"tags": ["latest"] | ||
}, | ||
"push": false | ||
}, | ||
"production": { | ||
"platforms": ["linux/amd64", "linux/arm64"], | ||
"provenance": "true", | ||
"push": true | ||
} | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/eslint:lint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["{projectRoot}/**/*.{ts,js,json}"], | ||
"maxWarnings": 0 | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"options": { | ||
"jestConfig": "{projectRoot}/jest.config.ts", | ||
"runInBand": true | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const BASE_URL = 'http://localhost:3333'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { BASE_URL } from './consts'; | ||
|
||
test('is alive', async () => { | ||
const response = await fetch(`${BASE_URL}/is-alive`); | ||
|
||
expect(response.status).toEqual(200); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "ES2022", | ||
"baseUrl": ".", | ||
"paths": { | ||
"@tests/*": ["./tests/*"] | ||
} | ||
}, | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
], | ||
"files": [], | ||
"include": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": ["jest.config.ts", "tests/**/*", "scripts/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.