-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci(root): Add Dockerfile and docker-compose #666
base: dev
Are you sure you want to change the base?
Changes from all commits
35eb6f4
09b5b4c
3cf3509
ff9dd05
5d2b0fa
38bb9f1
7daf678
8c05bf2
36cd42c
8524997
d779748
9578d7f
37c7cd8
e244d29
20119c1
415991c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules | ||
out | ||
.env |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
NODE_ENV=development | ||
DATABASE_URL=mysql://kampus:kampus@localhost:3306/kampus?schema=public | ||
NEXTAUTH_URL=http://localhost:3001/auth | ||
NEXT_PUBLIC_GQL_URL=http://localhost:4000/graphql | ||
AUTH_COOKIE_DOMAIN='' | ||
GITHUB_ID=3748376f66f395c5f36a | ||
GITHUB_SECRET=ae893fe55f3135f7d3f758b36116b52e06de552f | ||
DISCORD_ID='' | ||
DISCORD_SECRET='' | ||
TWITCH_ID='' | ||
TWITCH_SECRET='' | ||
NEXTAUTH_SECRET='Example' | ||
BUILD_STANDALONE=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Deploy Checks | ||
|
||
on: | ||
pull_request: | ||
branches: [ dev ] | ||
jobs: | ||
deploy_preview: | ||
name: Deploy Checks | ||
runs-on: ubuntu-latest | ||
permissions: | ||
deployments: write | ||
contents: read | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Install jq | ||
run: sudo apt-get update && sudo apt-get install -y jq | ||
- name: Build Docker Compose services | ||
run: docker-compose build | ||
- name: Start Docker Compose services | ||
run: docker-compose up -d | ||
- name: Check Docker Compose services are running | ||
run: | | ||
for service in $(docker-compose ps --services); do | ||
if [ "$(docker inspect -f '{{.State.Status}}' $service)" != "running" ]; then | ||
echo "Service $service is not running" | ||
exit 1 | ||
fi | ||
done | ||
- name: Shutdown Docker Compose services | ||
run: docker-compose down |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# syntax = docker/dockerfile:1 | ||
|
||
# base-node stage contains the environment variables and the node image with slim OS. | ||
FROM node:18 AS node-image | ||
# base-slim-node stage contains the environment variables and the node image with slim OS. | ||
FROM node:18-bullseye-slim AS node-slim-image | ||
# base-distroless stage contains the environment variables and the distroless image. | ||
FROM gcr.io/distroless/nodejs18-debian11 AS node-distroless-image | ||
|
||
# Base stage, install turbo and copy the project | ||
FROM node-slim-image AS base | ||
WORKDIR /app | ||
RUN npm install --global turbo | ||
COPY . . | ||
|
||
# kampus-prune stage, use "turbo" to get incremental builds and prune the workspace | ||
FROM base AS kampus-prune | ||
RUN turbo prune --scope=@kampus-apps/kampus --docker | ||
|
||
# gql-prune stage, use "turbo" to get incremental builds and prune the workspace | ||
FROM base AS gql-prune | ||
RUN turbo prune --scope=@kampus-apps/gql --docker | ||
|
||
# pasaport-prune stage, use "turbo" to get incremental builds and prune the workspace | ||
FROM base AS pasaport-prune | ||
RUN turbo prune --scope=@kampus-apps/pasaport --docker | ||
|
||
# kampus-builder stage, use "turbo" to build the project incrementally and get incremental builds | ||
FROM node-slim-image as kampus-builder | ||
WORKDIR /app | ||
COPY .gitignore .gitignore | ||
COPY --from=kampus-prune /app/out/json . | ||
COPY --from=kampus-prune /app/out/package-lock.json ./package-lock.json | ||
COPY /tsconfig.json tsconfig.json | ||
RUN npm install | ||
COPY --from=kampus-prune /app/out/full/ . | ||
COPY .env ./apps/pasaport/.env | ||
COPY turbo.json turbo.json | ||
RUN npx turbo build | ||
|
||
# python, g++, make, etc. are required for gql dependencies. node:18 is used as base image | ||
FROM node-image AS gql-builder | ||
WORKDIR /app | ||
COPY .gitignore .gitignore | ||
COPY --from=gql-prune /app/out/json . | ||
COPY --from=gql-prune /app/out/package-lock.json ./package-lock.json | ||
COPY /tsconfig.json tsconfig.json | ||
RUN npm install | ||
COPY --from=gql-prune /app/out/full/ . | ||
COPY .env ./apps/pasaport/.env | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @usirin should we make a small script to do this on local as well seems like right now .env.example files can run the applications so local env can utilise this too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from what i read from the next.js docs, the best practice is to switch to a
|
||
COPY turbo.json turbo.json | ||
RUN npx turbo build | ||
|
||
# pasaport-builder stage, use "turbo" to build the project incrementally and get incremental builds | ||
FROM node-slim-image AS pasaport-builder | ||
WORKDIR /app | ||
COPY .gitignore .gitignore | ||
COPY --from=pasaport-prune /app/out/json . | ||
COPY --from=pasaport-prune /app/out/package-lock.json ./package-lock.json | ||
COPY /tsconfig.json tsconfig.json | ||
RUN npm install | ||
COPY --from=pasaport-prune /app/out/full/ . | ||
COPY .env ./apps/pasaport/.env | ||
COPY turbo.json turbo.json | ||
RUN npx turbo build | ||
|
||
# Use distroless to reduce the minimum size of the image and reduce the attack surface | ||
#If you want to use npm, use the node:18-bullseye-slim image (prisma doesn't work with alpine arm64) | ||
# kampus stage - the dev server. | ||
FROM node-distroless-image as kampus | ||
COPY tsconfig.json ./tsconfig.json | ||
COPY --from=kampus-builder /app/apps/kampus/next.config.mjs . | ||
COPY --from=kampus-builder /app/apps/kampus/package.json . | ||
COPY --from=kampus-builder /app/apps/kampus/.next/standalone ./ | ||
COPY --from=kampus-builder /app/apps/kampus/.next/static ./apps/kampus/.next/static | ||
COPY --from=kampus-builder /app/apps/kampus/public ./apps/kampus/public | ||
CMD ["apps/kampus/server.js"] | ||
|
||
# gql stage - the dev server. | ||
FROM node-distroless-image as gql | ||
COPY tsconfig.json ./tsconfig.json | ||
COPY --from=gql-builder /app/apps/gql/next.config.mjs . | ||
COPY --from=gql-builder /app/apps/gql/package.json . | ||
COPY --from=gql-builder /app/apps/gql/.next/standalone ./ | ||
COPY --from=gql-builder /app/apps/gql/.next/static ./apps/gql/.next/static | ||
CMD ["apps/gql/server.js"] | ||
|
||
# pasaport stage - the dev server. | ||
FROM node-distroless-image as pasaport | ||
COPY tsconfig.json ./tsconfig.json | ||
COPY --from=pasaport-builder /app/apps/pasaport/next.config.mjs . | ||
COPY --from=pasaport-builder /app/apps/pasaport/package.json . | ||
COPY --from=pasaport-builder /app/apps/pasaport/.next/standalone ./ | ||
COPY --from=pasaport-builder /app/apps/pasaport/.next/static ./apps/pasaport/.next/static | ||
CMD ["apps/pasaport/server.js"] | ||
|
||
# ssl-proxy stage - the dev server. | ||
FROM node:18-bullseye-slim as proxy | ||
WORKDIR /app | ||
|
||
RUN npm i -g local-ssl-proxy | ||
RUN npm i -g concurrently | ||
|
||
# keep running | ||
CMD ["concurrently", "local-ssl-proxy --target 3000 --source 5000", "local-ssl-proxy --target 3001 --source 5001", "local-ssl-proxy --target 4000 --source 5002"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can turbo run these ? turbo has concurrent running capability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at this point we don't need turbo, we pruned everything, and i am not even sure if there is a turbo binary at this point. i think it's better to go with this. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
NODE_ENV=development | ||
DATABASE_URL=mysql://kampus:kampus@localhost:3306/kampus?schema=public | ||
NEXTAUTH_URL=http://pasaport.localhost.kamp.us:3001/auth | ||
BUILD_STANDALONE=false | ||
NEXTAUTH_URL=http://pasaport.localhost.kamp.us:3001/auth |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const config = { | ||
transpilePackages: ["@kampus/sozluk-content"], | ||
output: process.env.BUILD_STANDALONE === "true" ? "standalone" : undefined, | ||
}; | ||
|
||
export default config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ DISCORD_SECRET='' | |
TWITCH_ID='' | ||
TWITCH_SECRET='' | ||
NEXTAUTH_SECRET='Example' | ||
BUILD_STANDALONE=false |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ DISCORD_SECRET='' | |
TWITCH_ID='' | ||
TWITCH_SECRET='' | ||
NEXTAUTH_SECRET='Example' | ||
BUILD_STANDALONE=false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const config = { | ||
transpilePackages: ["@kampus/email", "@kampus/next-auth"], | ||
output: process.env.BUILD_STANDALONE === "true" ? "standalone" : undefined, | ||
}; | ||
|
||
export default config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason we have an example env at the root. Since we have examples per folder that's good to move there where it matches
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was for the GitHub workflow testing purposes, and I will remove it in this PR.
https://github.com/marketplace/actions/create-env-file will handle the .env file creation at GitHub workflow for deployment purposes