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:
parent
f60a6a0f47
commit
89e3d68168
6 changed files with 130 additions and 4 deletions
31
.dockerignore
Normal file
31
.dockerignore
Normal 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
|
2
.github/workflows/deploy-dev.yml
vendored
2
.github/workflows/deploy-dev.yml
vendored
|
@ -2,7 +2,7 @@ name: Deploy Dev
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
|
|
||||||
concurrency: deploy-dev
|
concurrency: deploy-dev
|
||||||
|
|
||||||
|
|
44
.github/workflows/dockerize.yml
vendored
Normal file
44
.github/workflows/dockerize.yml
vendored
Normal 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
29
Dockerfile
Normal 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
18
docker-compose.yml
Normal 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
|
|
@ -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));
|
const parameters = new Set(process.argv.slice(2));
|
||||||
export const noInquiry = parameters.has('--no-inquiry');
|
export const noInquiry = parameters.has('--no-inquiry') || isTrue(getEnv('NO_INQUIRY'));
|
||||||
export const fromRoot = parameters.has('--from-root');
|
export const fromRoot = parameters.has('--from-root') || isTrue(getEnv('FROM_ROOT'));
|
||||||
export const allYes = parameters.has('--all-yes');
|
export const allYes = parameters.has('--all-yes') || isTrue(getEnv('ALL_YES'));
|
||||||
|
|
Loading…
Reference in a new issue