Skip to content

Commit

Permalink
Merge pull request #288 from swisstopo/feature/assets-269_prod-sync-s…
Browse files Browse the repository at this point in the history
…ervice

Feature/assets 269 prod sync service
  • Loading branch information
vej-ananas authored Oct 16, 2024
2 parents 9e75c60 + a937870 commit 37a101f
Show file tree
Hide file tree
Showing 21 changed files with 236 additions and 108 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/publish-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ jobs:
DOCKERFILE: ./apps/client-asset-sg/docker/Dockerfile
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build_and_push_pipeline:
name: "build and push pipeline"
build_and_push_sync:
name: "build and push sync"
needs:
- determine_version
runs-on: ubuntu-latest
Expand All @@ -118,10 +118,10 @@ jobs:
- name: Create image
uses: ./.github/actions/create-image
with:
IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}-pipeline
IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}-sync
TAG: ${{ env.IS_EDGE == 'true' && 'edge' || '' }}
VERSION: ${{ needs.determine_version.outputs.version }}
DOCKERFILE: ./apps/pipeline-asset-sg/docker/Dockerfile
DOCKERFILE: ./apps/sync-asset-sg/docker/Dockerfile
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

tag_commit:
Expand All @@ -130,7 +130,7 @@ jobs:
- determine_version
- build_and_push_api
- build_and_push_app
- build_and_push_pipeline
- build_and_push_sync
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/publish-rc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,28 @@ jobs:
- name: Push docker image
run: docker push ${{ vars.BASE_IMAGE_NAME }}-api:release-candidate

tag_rc_image_pipeline:
name: tag rc image pipeline
tag_rc_image_sync:
name: tag rc image sync
runs-on: ubuntu-latest
steps:
- name: Login to GitHub Packages
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin

- name: Pull docker image
run: docker pull ${{ vars.BASE_IMAGE_NAME }}-pipeline:${{ env.BASE }}
run: docker pull ${{ vars.BASE_IMAGE_NAME }}-sync:${{ env.BASE }}

- name: Tag docker image
run: docker tag ${{ vars.BASE_IMAGE_NAME }}-pipeline:${{ env.BASE }} ${{ vars.BASE_IMAGE_NAME }}-pipeline:release-candidate
run: docker tag ${{ vars.BASE_IMAGE_NAME }}-sync:${{ env.BASE }} ${{ vars.BASE_IMAGE_NAME }}-sync:release-candidate

- name: Push docker image
run: docker push ${{ vars.BASE_IMAGE_NAME }}-pipeline:release-candidate
run: docker push ${{ vars.BASE_IMAGE_NAME }}-sync:release-candidate

tag_rc_commit:
name: "tag rc commit"
needs:
- tag_rc_image_app
- tag_rc_image_api
- tag_rc_image_pipeline
- tag_rc_image_sync
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ jobs:
DOCKERFILE: ./apps/client-asset-sg/docker/Dockerfile
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build_and_push_pipeline:
name: "build and push pipeline"
build_and_push_sync:
name: "build and push sync"
needs:
- determine_version
runs-on: ubuntu-latest
Expand All @@ -110,13 +110,13 @@ jobs:
- name: Create image
uses: ./.github/actions/create-image
with:
IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}-pipeline
IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}-sync
TAG: latest
OTHER_TAGS: |
type=raw,value=${{ env.IS_EDGE == 'true' && 'edge' || '' }}
type=raw,value=${{ env.IS_RC == 'true' && 'release-candidate' || '' }}
VERSION: ${{ needs.determine_version.outputs.version }}
DOCKERFILE: ./apps/pipeline-asset-sg/docker/Dockerfile
DOCKERFILE: ./apps/sync-asset-sg/docker/Dockerfile
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

tag_commit:
Expand All @@ -125,7 +125,7 @@ jobs:
- determine_version
- build_and_push_api
- build_and_push_app
- build_and_push_pipeline
- build_and_push_sync
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
- determine_version
- build_and_push_api
- build_and_push_app
- build_and_push_pipeline
- build_and_push_sync
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down Expand Up @@ -216,4 +216,4 @@ jobs:
await removePackageVersions(`${process.env.BASE_IMAGE_NAME}-api`, outdatedVersions);
await removePackageVersions(`${process.env.BASE_IMAGE_NAME}-app`, outdatedVersions);
await removePackageVersions(`${process.env.BASE_IMAGE_NAME}-pipeline`, outdatedVersions);
await removePackageVersions(`${process.env.BASE_IMAGE_NAME}-sync`, outdatedVersions);
39 changes: 0 additions & 39 deletions apps/pipeline-asset-sg/src/core/config.ts

This file was deleted.

20 changes: 0 additions & 20 deletions apps/pipeline-asset-sg/src/main.ts

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG APP_VERSION

FROM node:22-alpine as pipeline-builder
FROM node:22-alpine as sync-builder

ENV APP_VERSION=${APP_VERSION}
ENV NODE_ENV=development
Expand All @@ -9,7 +9,7 @@ WORKDIR /app
COPY . .

RUN npm install --no-scripts
RUN npx nx build pipeline-asset-sg --configuration=production
RUN npx nx build sync-asset-sg --configuration=production

# final image build
FROM node:22-alpine
Expand All @@ -18,8 +18,8 @@ ENV APP_VERSION=${APP_VERSION}
ENV NODE_ENV=production

WORKDIR /app
COPY --from=pipeline-builder /app/dist/apps/pipeline-asset-sg .
COPY --from=pipeline-builder /app/node_modules ./node_modules
COPY --from=sync-builder /app/dist/apps/sync-asset-sg .
COPY --from=sync-builder /app/node_modules ./node_modules

RUN addgroup -S app \
&& adduser -S app -G app \
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable */
export default {
displayName: 'pipeline-asset-sg',
displayName: 'sync-asset-sg',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/pipeline-asset-sg',
coverageDirectory: '../../coverage/apps/sync-asset-sg',
};
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"name": "pipeline-asset-sg",
"name": "sync-asset-sg",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/pipeline-asset-sg/src",
"sourceRoot": "apps/sync-asset-sg/src",
"projectType": "application",
"tags": [],
"targets": {
"build": {
"executor": "nx:run-commands",
"options": {
"parallel": false,
"tsConfig": "apps/pipeline-asset-sg/tsconfig.app.json",
"tsConfig": "apps/sync-asset-sg/tsconfig.app.json",
"commands": [
{
"command": "npm run prisma -- generate",
"forwardAllArgs": false
},
{
"command": "npx nx run pipeline-asset-sg:build-app:production"
"command": "npx nx run sync-asset-sg:build-app:production"
},
{
"command": "npx shx cp apps/pipeline-asset-sg/docker/* dist/apps/pipeline-asset-sg",
"command": "npx shx cp apps/sync-asset-sg/docker/* dist/apps/sync-asset-sg",
"forwardAllArgs": false
},
{
"command": "npx shx mkdir dist/apps/pipeline-asset-sg/prisma",
"command": "npx shx mkdir dist/apps/sync-asset-sg/prisma",
"forwardAllArgs": false
},
{
"command": "npx shx cp ./libs/persistence/prisma/schema.prisma dist/apps/pipeline-asset-sg/prisma/",
"command": "npx shx cp ./libs/persistence/prisma/schema.prisma dist/apps/sync-asset-sg/prisma/",
"forwardAllArgs": false
},
{
"command": "npx shx cp -R ./libs/persistence/prisma/migrations dist/apps/pipeline-asset-sg/prisma/",
"command": "npx shx cp -R ./libs/persistence/prisma/migrations dist/apps/sync-asset-sg/prisma/",
"forwardAllArgs": false
},
{
"command": "npx shx sed -i \"s/(\\.\\.\\/)*node_modules/\\.\\/node_modules/g\" dist/apps/pipeline-asset-sg/prisma/schema.prisma",
"command": "npx shx sed -i \"s/(\\.\\.\\/)*node_modules/\\.\\/node_modules/g\" dist/apps/sync-asset-sg/prisma/schema.prisma",
"forwardAllArgs": false
}
]
Expand All @@ -46,11 +46,11 @@
"outputs": ["{options.outputPath}"],
"options": {
"platform": "node",
"outputPath": "dist/apps/pipeline-asset-sg",
"outputPath": "dist/apps/sync-asset-sg",
"format": ["cjs"],
"bundle": false,
"main": "apps/pipeline-asset-sg/src/main.ts",
"tsConfig": "apps/pipeline-asset-sg/tsconfig.app.json",
"main": "apps/sync-asset-sg/src/main.ts",
"tsConfig": "apps/sync-asset-sg/tsconfig.app.json",
"generatePackageJson": true,
"esbuildOptions": {
"sourcemap": true,
Expand All @@ -71,34 +71,33 @@
}
}
},

"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "pipeline-asset-sg:build"
"buildTarget": "sync-asset-sg:build"
},
"configurations": {
"development": {
"buildTarget": "pipeline-asset-sg:build:development"
"buildTarget": "sync-asset-sg:build:development"
},
"production": {
"buildTarget": "pipeline-asset-sg:build:production"
"buildTarget": "sync-asset-sg:build:production"
}
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"eslintConfig": "apps/pipeline-asset-sg/eslint.config.js"
"eslintConfig": "apps/sync-asset-sg/eslint.config.js"
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "apps/pipeline-asset-sg/jest.config.ts"
"jestConfig": "apps/sync-asset-sg/jest.config.ts"
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions apps/sync-asset-sg/src/core/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export type Mode = 'view' | 'extern';

export interface SyncConfig {
mode: Mode;
source: {
connectionString: string;
allowedWorkgroupIds: number[];
};
destination: {
connectionString: string;
allowedWorkgroupIds: number[];
};
}

function getEnvOrThrow(key: string): string {
const value = process.env[key];
if (!value) {
throw new Error(`Missing environment variable: ${key}`);
}
return value;
}

export function getConfig(): SyncConfig {
return {
mode: getEnvOrThrow('MODE') as Mode,
source: {
connectionString: getEnvOrThrow('SOURCE_CONNECTION_STRING'),
allowedWorkgroupIds: process.env['SOURCE_WORKGROUP_IDS']?.split(',').map(Number) ?? [],
},
destination: {
connectionString: getEnvOrThrow('DESTINATION_CONNECTION_STRING'),
allowedWorkgroupIds: process.env['DESTINATION_WORKGROUP_IDS']?.split(',').map(Number),
},
};
}

export function prismaConfig(connectionString: string) {
return {
datasources: {
db: {
url: connectionString,
},
},
};
}

export function maskSecrets(config: SyncConfig): SyncConfig {
return {
...config,
source: {
...config.source,
connectionString: '****' + config.source.connectionString.split('@').pop(),
},
destination: {
...config.destination,
connectionString: '***' + config.destination.connectionString.split('@').pop(),
},
};
}
Loading

0 comments on commit 37a101f

Please sign in to comment.