CI
This commit is contained in:
8
.dockerignore
Normal file
8
.dockerignore
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
node_modules
|
||||||
|
.next
|
||||||
|
dist
|
||||||
|
.git
|
||||||
|
.github
|
||||||
|
*.md
|
||||||
|
.nx
|
||||||
|
.vscode
|
||||||
80
.github/workflows/ci.yml
vendored
80
.github/workflows/ci.yml
vendored
@@ -9,9 +9,14 @@ on:
|
|||||||
permissions:
|
permissions:
|
||||||
actions: read
|
actions: read
|
||||||
contents: read
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_PREFIX: ${{ github.repository }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
main:
|
lint-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -19,26 +24,69 @@ jobs:
|
|||||||
filter: tree:0
|
filter: tree:0
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
# This enables task distribution via Nx Cloud
|
|
||||||
# Run this command as early as possible, before dependencies are installed
|
|
||||||
# Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun
|
|
||||||
# Uncomment this line to enable task distribution
|
|
||||||
# - run: npx nx start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci"
|
|
||||||
|
|
||||||
# Cache node_modules
|
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npx cypress install
|
|
||||||
- uses: nrwl/nx-set-shas@v4
|
- uses: nrwl/nx-set-shas@v4
|
||||||
|
- run: npx nx affected -t lint test typecheck
|
||||||
|
|
||||||
# Prepend any command with "nx record --" to record its logs to Nx Cloud
|
build-api:
|
||||||
# - run: npx nx record -- echo Hello World
|
runs-on: ubuntu-latest
|
||||||
# When you enable task distribution, run the e2e-ci task instead of e2e
|
needs: lint-test
|
||||||
- run: npx nx affected -t lint test build typecheck e2e
|
steps:
|
||||||
# Nx Cloud recommends fixes for failures to help you get CI green faster. Learn more: https://nx.dev/ci/features/self-healing-ci
|
- uses: actions/checkout@v4
|
||||||
- run: npx nx fix-ci
|
|
||||||
if: always()
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to GitHub Container Registry
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push API image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: apps/api/Dockerfile
|
||||||
|
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
|
||||||
|
tags: |
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/api:latest
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/api:${{ github.sha }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
build-web:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: lint-test
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to GitHub Container Registry
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push Web image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: apps/web/Dockerfile
|
||||||
|
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
|
||||||
|
tags: |
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/web:latest
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/web:${{ github.sha }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|||||||
27
apps/api/Dockerfile
Normal file
27
apps/api/Dockerfile
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
FROM node:20-alpine AS base
|
||||||
|
|
||||||
|
FROM base AS deps
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
COPY apps/api/package.json ./apps/api/
|
||||||
|
COPY libs/shared/package.json ./libs/shared/
|
||||||
|
RUN npm ci --omit=dev
|
||||||
|
|
||||||
|
FROM base AS build
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
COPY apps/api/package.json ./apps/api/
|
||||||
|
COPY libs/shared/package.json ./libs/shared/
|
||||||
|
RUN npm ci
|
||||||
|
COPY nx.json tsconfig.base.json ./
|
||||||
|
COPY libs/ ./libs/
|
||||||
|
COPY apps/api/ ./apps/api/
|
||||||
|
RUN npx nx build api
|
||||||
|
|
||||||
|
FROM base AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY --from=build /app/apps/api/dist ./dist
|
||||||
|
EXPOSE 3000
|
||||||
|
CMD ["node", "dist/main.js"]
|
||||||
32
apps/web/Dockerfile
Normal file
32
apps/web/Dockerfile
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
FROM node:20-alpine AS base
|
||||||
|
|
||||||
|
FROM base AS deps
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
COPY apps/web/package.json ./apps/web/
|
||||||
|
COPY libs/shared/package.json ./libs/shared/
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
FROM base AS build
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY package.json package-lock.json nx.json tsconfig.base.json ./
|
||||||
|
COPY libs/ ./libs/
|
||||||
|
COPY apps/web/ ./apps/web/
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
RUN npx nx build web
|
||||||
|
|
||||||
|
FROM base AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
|
RUN adduser --system --uid 1001 nextjs
|
||||||
|
COPY --from=build /app/apps/web/.next/standalone ./
|
||||||
|
COPY --from=build /app/apps/web/.next/static ./apps/web/.next/static
|
||||||
|
COPY --from=build /app/apps/web/public ./apps/web/public
|
||||||
|
USER nextjs
|
||||||
|
EXPOSE 8888
|
||||||
|
ENV PORT=8888
|
||||||
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
CMD ["node", "apps/web/server.js"]
|
||||||
@@ -10,6 +10,7 @@ const nextConfig = {
|
|||||||
// Use this to set Nx-specific options
|
// Use this to set Nx-specific options
|
||||||
// See: https://nx.dev/recipes/next/next-config-setup
|
// See: https://nx.dev/recipes/next/next-config-setup
|
||||||
nx: {},
|
nx: {},
|
||||||
|
output: 'standalone',
|
||||||
async redirects() {
|
async redirects() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user