diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..62e2ada24 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,31 @@ +# dependencies +node_modules + +# testing +/packages/*/coverage + +# report +/report.json +/packages/*/report.json + +# production +/packages/*/build +/packages/*/lib +/packages/*/dist + +# logs +logs +*.log* + +# misc +cache +.*cache +.DS_Store +*.env +.idea/ +*.pem +.history +.vscode +.git +.github +.gitignore diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 395e93981..70332eb94 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -2,7 +2,7 @@ name: Deploy Dev on: push: - branches: [ master ] + branches: [master] concurrency: deploy-dev diff --git a/.github/workflows/dockerize.yml b/.github/workflows/dockerize.yml new file mode 100644 index 000000000..938447ebc --- /dev/null +++ b/.github/workflows/dockerize.yml @@ -0,0 +1,44 @@ +name: Dockerize + +on: + push: + branches: [master] + +concurrency: + group: dockerize-${{ github.ref }} + cancel-in-progress: true + +jobs: + dockerize: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and export + uses: docker/build-push-action@v3 + with: + context: . + tags: logto + outputs: type=docker,dest=/tmp/logto.tar + + - name: Load image + run: docker load -i /tmp/logto.tar + + - name: Compose up + run: docker compose up -d + + - name: Sleep for 30 seconds + run: sleep 30s + + - name: Health check + run: curl http://localhost:3001/api/status -If + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: logto.${{ github.sha }} + path: /tmp/logto.tar diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..76d3c9277 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Build stage +FROM node:16-alpine as builder +WORKDIR /etc/logto +ENV CI=true +COPY . . + +# Install toolchain +RUN npm add --location=global pnpm@^7.2.1 +# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#node-gyp-alpine +RUN apk add --no-cache python3 make g++ + +# Install dependencies and build +RUN pnpm i +RUN pnpm -- lerna run build --stream + +# Prune dependencies for production +RUN rm -rf node_modules packages/*/node_modules +RUN NODE_ENV=production pnpm i + +# Clean up +RUN rm -rf .parcel-cache pnpm-*.yaml + +# Seal stage +FROM node:16-alpine as app +WORKDIR /etc/logto +COPY --from=builder /etc/logto . +EXPOSE 3001 +ENV NO_INQUIRY true +ENTRYPOINT ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..1fdf37fa9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +# This compose file is for demonstration only, do not use in prod. +version: "3.9" +services: + app: + depends_on: + - postgres + image: logto:latest + ports: + - 3001:3001 + environment: + ALL_YES: 1 + NO_INQUIRY: 0 + DB_URL_DEFAULT: postgres://postgres:p0stgr3s@postgres:5432 + postgres: + image: postgres:14-alpine + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: p0stgr3s diff --git a/packages/core/src/env-set/parameters.ts b/packages/core/src/env-set/parameters.ts index 71e83c367..667847af8 100644 --- a/packages/core/src/env-set/parameters.ts +++ b/packages/core/src/env-set/parameters.ts @@ -1,4 +1,8 @@ +import { getEnv } from '@silverhand/essentials'; + +const isTrue = (value: string) => ['1', 'true', 'y', 'yes', 'yep', 'yeah'].includes(value); + const parameters = new Set(process.argv.slice(2)); -export const noInquiry = parameters.has('--no-inquiry'); -export const fromRoot = parameters.has('--from-root'); -export const allYes = parameters.has('--all-yes'); +export const noInquiry = parameters.has('--no-inquiry') || isTrue(getEnv('NO_INQUIRY')); +export const fromRoot = parameters.has('--from-root') || isTrue(getEnv('FROM_ROOT')); +export const allYes = parameters.has('--all-yes') || isTrue(getEnv('ALL_YES'));