-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
485 additions
and
541 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: 🐳 Build And Push Docker Image | ||
on: | ||
workflow_call: | ||
inputs: | ||
tag: | ||
type: string | ||
description: The tag to push to the Docker registry. | ||
# required: true | ||
# default: latest | ||
|
||
jobs: | ||
build: | ||
name: 🐳 Build | ||
# only build/deploy main branch on pushes | ||
# if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name == 'push' }} | ||
if: ${{ (github.ref == 'refs/heads/main') && github.event_name == 'push' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: ⬇️ Checkout repo | ||
uses: actions/[email protected] | ||
|
||
- name: 🧑💻 Login to Docker Hub | ||
uses: docker/[email protected] | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
logout: true | ||
|
||
- name: 🐳 Set up Docker Buildx | ||
uses: docker/[email protected] | ||
|
||
# Setup cache | ||
- name: ⚡️ Cache Docker layers | ||
uses: actions/[email protected] | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }}-${{ github.ref_name }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: 🐳 Build Production Image | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
push: true | ||
tags: varkoff/nestjs-remix-monorepo:production | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new | ||
|
||
# - name: 🐳 Build Staging Image | ||
# if: ${{ github.ref == 'refs/heads/dev' }} | ||
# uses: docker/[email protected] | ||
# with: | ||
# context: . | ||
# push: true | ||
# tags: varkoff/nestjs-remix-monorepo:latest | ||
|
||
# cache-from: type=local,src=/tmp/.buildx-cache | ||
# cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new | ||
|
||
# This ugly bit is necessary if you don't want your cache to grow forever | ||
# till it hits GitHub's limit of 5GB. | ||
# Temp fix | ||
# https://github.com/docker/build-push-action/issues/252 | ||
# https://github.com/moby/buildkit/issues/1896 | ||
- name: 🚚 Move cache | ||
run: | | ||
rm -rf /tmp/.buildx-cache | ||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
name: 🚀 Deploy | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
pull_request: {} | ||
|
||
permissions: | ||
actions: write | ||
contents: read | ||
|
||
jobs: | ||
lint: | ||
name: ⬣ ESLint | ||
runs-on: ubuntu-latest | ||
env: | ||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} | ||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} | ||
TURBO_REMOTE_ONLY: true | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 2 | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'npm' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build Application | ||
run: npm run build | ||
|
||
- name: 🔬 Lint | ||
run: npm run lint | ||
|
||
typecheck: | ||
name: ʦ TypeScript | ||
runs-on: ubuntu-latest | ||
env: | ||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} | ||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} | ||
TURBO_REMOTE_ONLY: true | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 2 | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'npm' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build Application | ||
run: npm run build | ||
|
||
- name: 🔎 Type check | ||
run: npm run typecheck --if-present | ||
|
||
build: | ||
name: 🐳 build | ||
uses: ./.github/workflows/build.yml | ||
secrets: inherit | ||
|
||
deploy: | ||
name: 🚀 Deploy | ||
runs-on: [self-hosted] | ||
needs: [build, lint, typecheck] | ||
# needs: [build] | ||
# only build/deploy main branch on pushes | ||
# if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name == 'push' }} | ||
if: ${{ (github.ref == 'refs/heads/main') && github.event_name == 'push' }} | ||
env: | ||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} | ||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} | ||
TURBO_REMOTE_ONLY: true | ||
|
||
steps: | ||
- name: Cache node modules | ||
uses: actions/[email protected] | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- name: ⬇️ Checkout repo | ||
uses: actions/[email protected] | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
# - name: 🚀 Run Docker Compose on Staging | ||
# if: ${{ github.ref == 'refs/heads/dev' }} | ||
# env: | ||
# NODE_ENV: staging | ||
# run: | | ||
# docker pull varkoff/nestjs-remix-monorepo:latest | ||
# docker compose -f docker-compose.staging.yaml up -d | ||
# docker system prune --all --volumes --force | ||
|
||
- name: 🚀 Run Docker Compose on Production | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
env: | ||
NODE_ENV: production | ||
run: | | ||
docker pull varkoff/nestjs-remix-monorepo:production | ||
docker compose -f docker-compose.prod.yaml up -d | ||
docker system prune --all --volumes --force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,4 @@ pids | |
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
FROM --platform=amd64 node:18-alpine As base | ||
|
||
FROM base AS builder | ||
|
||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. | ||
RUN apk add --no-cache libc6-compat | ||
RUN apk update | ||
# Set working directory | ||
WORKDIR /app | ||
RUN npm install --global turbo | ||
COPY --chown=node:node . . | ||
RUN turbo prune @virgile/backend --docker | ||
|
||
# Add lockfile and package.json's of isolated subworkspace | ||
FROM base AS installer | ||
RUN apk add --no-cache libc6-compat | ||
RUN apk update | ||
WORKDIR /app | ||
|
||
# First install the dependencies (as they change less often) | ||
COPY .gitignore .gitignore | ||
COPY --chown=node:node --from=builder /app/out/json/ . | ||
COPY --chown=node:node --from=builder /app/out/package-lock.json ./package-lock.json | ||
RUN npm install | ||
|
||
# Build the project | ||
COPY --from=builder /app/out/full/ . | ||
COPY turbo.json turbo.json | ||
|
||
# Uncomment and use build args to enable remote caching | ||
ARG TURBO_TEAM | ||
ENV TURBO_TEAM=$TURBO_TEAM | ||
|
||
ARG TURBO_TOKEN | ||
ENV TURBO_TOKEN=$TURBO_TOKEN | ||
ENV TZ=Europe/Paris | ||
ENV NODE_ENV="production" | ||
|
||
# ADD api/prisma api/prisma | ||
|
||
# RUN cd api && npx prisma generate | ||
|
||
RUN npm run build | ||
|
||
FROM base AS runner | ||
WORKDIR /app | ||
|
||
# Don't run production as root | ||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 remix-api | ||
USER remix-api | ||
|
||
# ENV TZ=Europe/Paris | ||
# ENV NODE_ENV="production" | ||
|
||
COPY --chown=remix-api:nodejs --from=installer /app/backend/package.json ./backend/package.json | ||
COPY --chown=remix-api:nodejs --from=installer /app/backend/dist ./backend/dist | ||
COPY --chown=remix-api:nodejs --from=installer /app/node_modules ./node_modules | ||
COPY --chown=remix-api:nodejs --from=installer /app/node_modules/@virgile/frontend ./node_modules/@virgile/frontend | ||
COPY --chown=remix-api:nodejs --from=installer /app/node_modules/@virgile/typescript-config ./node_modules/@virgile/typescript-config | ||
COPY --chown=remix-api:nodejs --from=installer /app/node_modules/@virgile/eslint-config ./node_modules/@virgile/eslint-config | ||
|
||
COPY --chown=remix-api:nodejs --from=builder /app/backend/start.sh ./backend/start.sh | ||
|
||
# RUN cd backend && npm run start | ||
ENTRYPOINT [ "backend/start.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Dockerfile | ||
.dockerignore | ||
node_modules | ||
npm-debug.log | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
cd backend | ||
# npx prisma migrate deploy | ||
npm run start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
services: | ||
monorepo_dev: | ||
environment: | ||
- NODE_ENV | ||
|
||
container_name: nestjs-remix-monorepo-dev | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
# image: varkoff/nestjs-remix-monorepo:dev | ||
restart: always | ||
ports: | ||
- 3000:3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
services: | ||
monorepo_prod: | ||
environment: | ||
- NODE_ENV | ||
|
||
container_name: nestjs-remix-monorepo-prod | ||
# build: | ||
# context: . | ||
# dockerfile: Dockerfile | ||
image: varkoff/nestjs-remix-monorepo:production | ||
restart: always | ||
ports: | ||
- 3000:3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
/node_modules | ||
*.log | ||
.DS_Store | ||
.env | ||
/.cache | ||
/public/build | ||
/build |
Oops, something went wrong.