diff --git a/README.OGCIO.md b/README.OGCIO.md index 18132c3eb09..8efdd898638 100644 --- a/README.OGCIO.md +++ b/README.OGCIO.md @@ -38,11 +38,11 @@ You can also run Logto natively on your machine outside the docker container. If you start Logto natively, the database won't be available, and you will have to start it separately. The database is still dockerized and has its own Docker Compose configuration. Use the following command to start the database container: -`docker compose -f docker-compose-db.yml up -d` +`docker compose -f docker-compose-local.yml up -d postgres` With the following command, you can shut down the database container: -`docker compose -f docker-compose-db.yml down` +`docker compose -f docker-compose-local.yml down postgres` ### Configuration and installation @@ -58,8 +58,8 @@ ADMIN_PORT=3302 PORT=3301 # OGCIO Config -USER_DEFAULT_ORGANIZATION_NAMES=OGCIO Seeded Org -USER_DEFAULT_ORGANIZATION_ROLE_NAMES=OGCIO Employee, OGCIO Manager +MOCK_TOKEN_ENDPOINT=http://localhost:4005/logto/mock/token +MOCK_KEYS_ENDPOINT=http://localhost:4005/logto/mock/keys ``` 2. Run the makefile command ``` diff --git a/azure_pipelines.yml b/azure_pipelines.yml index 4085f714049..10e6680d1ad 100644 --- a/azure_pipelines.yml +++ b/azure_pipelines.yml @@ -84,3 +84,25 @@ stages: awsServiceConnection: ${{ variables.awsServiceConnection }} awsRegion: ${{ variables.awsRegion }} serviceName: logto-admin + - stage: Build_MyGovId_Mock + displayName: Build MyGovId Mock + dependsOn: + - securityScan + condition: or(eq(variables['Build.SourceBranchName'], 'dev'),eq(variables['Build.Reason'], 'PullRequest')) + jobs: + - template: pipeline-templates/build_service.yml + parameters: + serviceName: mygovid-mock-service + pushArtefacts: true + buildArguments: $(buildArguments) + dockerfile: ./mygovid-mock-service/Dockerfile + - stage: Push_MyGovId_Mock + displayName: Push MyGovId Mock to ECR + dependsOn: Build_MyGovId_Mock + condition: eq(variables['Build.SourceBranchName'], 'dev') + jobs: + - template: pipeline-templates/push_image.yml + parameters: + awsServiceConnection: ${{ variables.awsServiceConnection }} + awsRegion: ${{ variables.awsRegion }} + serviceName: mygovid-mock-service diff --git a/docker-compose-db.yml b/docker-compose-db.yml deleted file mode 100644 index 1a1e4bf2e8e..00000000000 --- a/docker-compose-db.yml +++ /dev/null @@ -1,22 +0,0 @@ -# This file has been added on OGCIO fork -services: - postgres: - image: postgres:14-alpine - user: postgres - volumes: - - db:/var/lib/postgresql/data - environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: p0stgr3s - PGPORT: 5433 - healthcheck: - test: [ "CMD-SHELL", "pg_isready" ] - interval: 10s - timeout: 5s - retries: 5 - ports: - - 5433:5433 - -volumes: - db: - driver: local diff --git a/docker-compose-ogcio-logto.yml b/docker-compose-ogcio-logto.yml new file mode 100644 index 00000000000..0fb71523cb8 --- /dev/null +++ b/docker-compose-ogcio-logto.yml @@ -0,0 +1,61 @@ +# This file has been added on OGCIO fork +services: + app: + depends_on: + postgres: + condition: service_healthy + mygovid-mock-service: + condition: service_started + image: 730335224023.dkr.ecr.eu-west-1.amazonaws.com/life-events-logto:dev + entrypoint: + [ + "sh", + "-c", + "npm run cli db seed -- --swe && npm run cli db alteration deploy latest && npm run cli db ogcio -- --seeder-filepath=\"/etc/logto/packages/cli/src/commands/database/ogcio/ogcio-seeder-local.json\" && npm start" + ] + ports: + - 3301:3301 + - 3302:3302 + environment: + - TRUST_PROXY_HEADER=1 + - DB_URL=postgres://postgres:p0stgr3s@postgres:5433/logto + # Mandatory for GitPod to map host env to the container, thus GitPod can dynamically configure the public URL of Logto; + # Or, you can leverage it for local testing. + - ENDPOINT + - ADMIN_ENDPOINT + - PORT=3301 + - ADMIN_PORT=3302 + - MOCK_TOKEN_ENDPOINT=http://mygovid-mock-service:4005/logto/mock/token + - MOCK_KEYS_ENDPOINT=http://mygovid-mock-service:4005/logto/mock/keys + + postgres: + image: postgres:14-alpine + user: postgres + volumes: + - db:/var/lib/postgresql/data + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: p0stgr3s + PGPORT: 5433 + healthcheck: + test: [ "CMD-SHELL", "pg_isready" ] + interval: 10s + timeout: 5s + retries: 5 + ports: + - 5433:5433 + + mygovid-mock-service: + image: mygovid-mock-service:latest + build: + dockerfile: ./mygovid-mock-service/Dockerfile + ports: + - 4005:4005 + +volumes: + db: + driver: local + +networks: + logto_network: + external: true diff --git a/makefile b/makefile index 9c8ad70eabe..49ddf394a5f 100644 --- a/makefile +++ b/makefile @@ -11,7 +11,7 @@ down: docker-compose -f docker-compose-local.yml down run-native: @echo "${GREEN}Starting db...${NC}" - docker compose -f docker-compose-db.yml up --detach + docker compose -f docker-compose-local.yml up --detach postgres @echo "${GREEN}Db started!${NC}" @echo "${GREEN}Installing stuffs...${NC}" pnpm pnpm:devPreinstall && pnpm i && pnpm prepack diff --git a/mygovid-mock-service/.dockerignore b/mygovid-mock-service/.dockerignore new file mode 100644 index 00000000000..f06235c460c --- /dev/null +++ b/mygovid-mock-service/.dockerignore @@ -0,0 +1,2 @@ +node_modules +dist diff --git a/mygovid-mock-service/Dockerfile b/mygovid-mock-service/Dockerfile new file mode 100644 index 00000000000..9aafaa0bc1e --- /dev/null +++ b/mygovid-mock-service/Dockerfile @@ -0,0 +1,28 @@ +FROM node:20-alpine as builder + +WORKDIR /app + +COPY ./mygovid-mock-service/package*.json ./ + +RUN npm i + +COPY ./mygovid-mock-service ./ + +RUN npm run build + +FROM node:20-alpine AS runtime + +WORKDIR /app + +COPY --from=builder /app/node_modules /app/node_modules +COPY --from=builder /app/package*.json /app/ +COPY --from=builder /app /app/ + +ENV NODE_ENV=development +ENV LOG_LEVEL=trace + +RUN npm prune --omit=dev + +EXPOSE 4005 + +CMD [ "node", "dist/", "index.js" ] diff --git a/mygovid-mock-service/package.json b/mygovid-mock-service/package.json index 9f9eb2df5fd..a953da5c34c 100644 --- a/mygovid-mock-service/package.json +++ b/mygovid-mock-service/package.json @@ -8,7 +8,7 @@ "start": "node dist/index.js", "dev": "nodemon | pino-pretty", "lint": "eslint . --ext .ts", - "build": "echo Build script for the MyGovId mock service not needed so far" + "build": "rm -rf dist && tsc -p tsconfig.json && cp -r src/routes/static dist/routes/static" }, "nodemonConfig": { "ext": "ts,json", diff --git a/mygovid-mock-service/src/index.ts b/mygovid-mock-service/src/index.ts index 0b26cb15f28..de49adf0722 100644 --- a/mygovid-mock-service/src/index.ts +++ b/mygovid-mock-service/src/index.ts @@ -1,6 +1,6 @@ import { build } from "./app.js"; -const app = await build(); +const app = await build({logger: true}); app.listen({ host: "0.0.0.0", port: 4005 }, (err, address) => { if (err) { diff --git a/mygovid-mock-service/src/routes/logto/index.ts b/mygovid-mock-service/src/routes/logto/index.ts index 9f62eb86377..803d79b696f 100644 --- a/mygovid-mock-service/src/routes/logto/index.ts +++ b/mygovid-mock-service/src/routes/logto/index.ts @@ -27,7 +27,6 @@ export default async function login(app: FastifyInstance) { "/auth", { schema: { - tags: ["Mock"], querystring: { response_type: Type.String(), client_id: Type.String(), @@ -102,7 +101,6 @@ export default async function login(app: FastifyInstance) { "/token", { schema: { - tags: ["Mock"], body: Type.Object({ code: Type.String(), grant_type: Type.String(), @@ -157,7 +155,6 @@ export default async function login(app: FastifyInstance) { "/keys", { schema: { - tags: ["Mock"], response: { 200: Type.Object({ keys: Type.Array( diff --git a/packages/cli/src/commands/database/ogcio/ogcio-seeder-local.json b/packages/cli/src/commands/database/ogcio/ogcio-seeder-local.json index e5ce3f2b881..edf180ff1aa 100644 --- a/packages/cli/src/commands/database/ogcio/ogcio-seeder-local.json +++ b/packages/cli/src/commands/database/ogcio/ogcio-seeder-local.json @@ -127,11 +127,11 @@ "scope": "openid profile email", "clientId": "mock_client_id", "clientSecret": "mock_client_secret", - "tokenEndpoint": "http://localhost:4005/logto/mock/token", + "tokenEndpoint": "", "authorizationEndpoint": "http://localhost:4005/logto/mock/auth", "tokenEndpointAuthMethod": "client_secret_post", "idTokenVerificationConfig": { - "jwksUri": "http://localhost:4005/logto/mock/keys" + "jwksUri": "" }, "clientSecretJwtSigningAlgorithm": "HS256" }, diff --git a/pipeline-templates/build_service.yml b/pipeline-templates/build_service.yml index 4d80543aa10..b6b3caa307e 100644 --- a/pipeline-templates/build_service.yml +++ b/pipeline-templates/build_service.yml @@ -5,6 +5,8 @@ parameters: default: false - name: buildArguments default: "" + - name: dockerfile + default: "./Dockerfile" jobs: - job: Build @@ -17,7 +19,7 @@ jobs: inputs: command: build repository: ${{ parameters.serviceName }} - dockerfile: ./Dockerfile + dockerfile: ${{ parameters.dockerfile }} buildContext: '$(Build.SourcesDirectory)' arguments: ${{ parameters.buildArguments }} - task: Docker@0