Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18938] Improve DX #71

Merged
merged 23 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.OGCIO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
```
Expand Down
22 changes: 22 additions & 0 deletions azure_pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 0 additions & 22 deletions docker-compose-db.yml

This file was deleted.

61 changes: 61 additions & 0 deletions docker-compose-ogcio-logto.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mygovid-mock-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
28 changes: 28 additions & 0 deletions mygovid-mock-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
2 changes: 1 addition & 1 deletion mygovid-mock-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion mygovid-mock-service/src/index.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions mygovid-mock-service/src/routes/logto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default async function login(app: FastifyInstance) {
"/auth",
{
schema: {
tags: ["Mock"],
querystring: {
response_type: Type.String(),
client_id: Type.String(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -157,7 +155,6 @@ export default async function login(app: FastifyInstance) {
"/keys",
{
schema: {
tags: ["Mock"],
response: {
200: Type.Object({
keys: Type.Array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@
"scope": "openid profile email",
"clientId": "mock_client_id",
"clientSecret": "mock_client_secret",
"tokenEndpoint": "http://localhost:4005/logto/mock/token",
"tokenEndpoint": "<MOCK_TOKEN_ENDPOINT>",
"authorizationEndpoint": "http://localhost:4005/logto/mock/auth",
"tokenEndpointAuthMethod": "client_secret_post",
"idTokenVerificationConfig": {
"jwksUri": "http://localhost:4005/logto/mock/keys"
"jwksUri": "<MOCK_KEYS_ENDPOINT>"
},
"clientSecretJwtSigningAlgorithm": "HS256"
},
Expand Down
4 changes: 3 additions & 1 deletion pipeline-templates/build_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ parameters:
default: false
- name: buildArguments
default: ""
- name: dockerfile
default: "./Dockerfile"

jobs:
- job: Build
Expand All @@ -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
Expand Down