0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

ci: dockerize (#1190)

* ci: dockerize

* ci: fix docker compose

* ci: run dockerize on master push only

* refactor: add .gitignore to .dockerignore
This commit is contained in:
Gao Sun 2022-06-23 19:17:02 +08:00 committed by GitHub
parent f60a6a0f47
commit 89e3d68168
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 130 additions and 4 deletions

31
.dockerignore Normal file
View file

@ -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

44
.github/workflows/dockerize.yml vendored Normal file
View file

@ -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

29
Dockerfile Normal file
View file

@ -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"]

18
docker-compose.yml Normal file
View file

@ -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

View file

@ -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'));