Skip to content
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

Menambahkan opsi penggunaan docker #45

Merged
merged 42 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
bf5a2cd
feat: experiment push docker
reacto11mecha Jun 22, 2024
01d55aa
feat: trigger setiap push
reacto11mecha Jun 22, 2024
97c341a
fix: mengikuti docs turborepo
reacto11mecha Jun 22, 2024
b20905c
fix: rename
reacto11mecha Jun 22, 2024
ccdcc38
feat: menambahkan db migrator
reacto11mecha Jun 22, 2024
ac31e1f
feat: menambahkan shell script untuk start web docker
reacto11mecha Jun 22, 2024
787ff9e
fix: lupa tsup
reacto11mecha Jun 22, 2024
5a39906
fix: build typing sebelum actual build
reacto11mecha Jun 22, 2024
64a1775
fix: ganti posisi
reacto11mecha Jun 22, 2024
95597f8
fix: di ignore
reacto11mecha Jun 22, 2024
75b6f31
fix: rename ignore
reacto11mecha Jun 22, 2024
3fd6522
fix: mencoba untuk buat typing pada saat build api
reacto11mecha Jun 22, 2024
235f64e
fix: build -> type-build
reacto11mecha Jun 22, 2024
80a885c
fix: debug process
reacto11mecha Jun 22, 2024
974f99d
fix: harus ditambah ke daftar allow env
reacto11mecha Jun 22, 2024
cb8ffe6
fix: debug env (lagi)
reacto11mecha Jun 22, 2024
b132494
fix: update global env
reacto11mecha Jun 22, 2024
7c97cf8
fix: mau ga mau
reacto11mecha Jun 22, 2024
5bbc72e
fix: system wide?
reacto11mecha Jun 22, 2024
6c1afc2
fix?
reacto11mecha Jun 22, 2024
ac951f0
fix??
reacto11mecha Jun 22, 2024
033f043
fix???
reacto11mecha Jun 22, 2024
d60ca9e
fix: harus versi stabil dulu kah
reacto11mecha Jun 22, 2024
c66de1f
fix: init dulu, abistu install
reacto11mecha Jun 22, 2024
42d91c3
fix: output langsung nama file spesifik
reacto11mecha Jun 22, 2024
e118e90
fix: memperbaiki db-migrate
reacto11mecha Jun 22, 2024
e502a4d
fix: set linker menjadi node modules
reacto11mecha Jun 22, 2024
75b9752
chore: debug lagi
reacto11mecha Jun 22, 2024
65b9af3
chore: debug lagi (2)
reacto11mecha Jun 22, 2024
d3332f1
fix: salah file
reacto11mecha Jun 22, 2024
c113ef8
fix: menyalakan support standalone
reacto11mecha Jun 22, 2024
0477758
feat: mengaktifkan push dockerhub
reacto11mecha Jun 22, 2024
9fa2a05
feat: memperbaiki auth js
reacto11mecha Jun 22, 2024
5985094
feat: memperbaiki script migrator
reacto11mecha Jun 22, 2024
c85372f
feat: memperbaiki db migrator
reacto11mecha Jun 22, 2024
e5aebdb
fix: buat folder uploads
reacto11mecha Jun 24, 2024
0f8c1b3
fix: memperbaiki versi package
reacto11mecha Jun 24, 2024
5c85e1f
fix: what
reacto11mecha Jun 24, 2024
64767cc
fix: memperbaiki typing
reacto11mecha Jun 24, 2024
3a8082c
fix: lint
reacto11mecha Jun 24, 2024
ec4872d
feat: menambahkan docker compose
reacto11mecha Jun 24, 2024
314b0b3
feat: ketinggalan
reacto11mecha Jun 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Docker Image Build CI

on:
push:
# branches:
# - main

jobs:
web:
if: github.repository == 'sora-vp/baseline'

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build the Docker image
uses: docker/build-push-action@v5
with:
context: .
file: "./apps/web/Dockerfile"
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/sora-baseline-web:${{ github.ref_name }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ dist/

# web app
apps/web/public/uploads

# docker
./db
2 changes: 1 addition & 1 deletion apps/processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"dotenv-cli": "^7.4.1",
"eslint": "^9.2.0",
"prettier": "^3.2.5",
"tsup": "^8.0.2",
"tsup": "^8.1.0",
"tsx": "^4.9.4",
"typescript": "^5.4.5"
},
Expand Down
97 changes: 97 additions & 0 deletions apps/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
FROM node:20 AS base
# LABEL fly_launch_runtime="Next.js"
ENV NEXT_TELEMETRY_DISABLED=1
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.

RUN <<EOF
apt-get update -y
apt-get install libc6 libc++1 bash -y
corepack enable
EOF

FROM base AS with-turbo
RUN npm install -g turbo

FROM with-turbo AS pruned-repo
WORKDIR /app

COPY . .
RUN turbo prune @sora-vp/web @sora-vp/db @sora-vp/db-migrate --docker

FROM with-turbo as builder
WORKDIR /app

# First install dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=pruned-repo /app/out/json/ .
COPY --from=pruned-repo /app/out/yarn.lock ./yarn.lock
RUN yarn install --immutable

# Build the project and its dependencies
COPY --from=pruned-repo /app/out/full/ .
COPY turbo.json turbo.json

## This would be useful for browser environment variables that are actually baked at build time and you aren't passing them in otherwise.
# COPY .env.production .env.production
RUN CI=true SKIP_ENV_VALIDATION=true DB_HOST="something" DB_NAME="something" DB_USERNAME="something" DB_PASSWORD="something" turbo run build --filter=@sora-vp/web... --filter=@sora-vp/db-migrate...

# Debugging purpose
# RUN <<EOF
# apt-get install tree
# tree /app
# EOF

WORKDIR /app/packages/db-migrate
RUN <<EOF
mkdir -p /db-migrate
yarn set version stable
yarn pack -o /db-migrate/out.tgz
cd /db-migrate
echo '{ "name": "db-migrate", "type": "module" }' > package.json
echo "nodeLinker: node-modules" > .yarnrc.yml
yarn set version stable
yarn add ./out.tgz
EOF

# This is the fly.io release_command that performs a migration
COPY <<EOF /db-migrate/db-migrate-release-command.sh
#!/bin/bash
set -e
cd /db-migrate
node node_modules/@sora-vp/db-migrate/dist/index.js
EOF

FROM base AS runner
# Don't run production as root
RUN <<EOF
addgroup --system --gid 1001 nodejs
adduser --system --uid 1001 nextjs
EOF

USER nextjs

COPY --from=builder --chown=nextjs:nodejs /db-migrate /db-migrate

WORKDIR /app

EXPOSE 3000
ENV PORT=3000
ENV AUTH_TRUST_HOST=true

ENV NODE_ENV=production

COPY --from=builder --chown=nextjs:nodejs /app/apps/web/next.config.js .
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/package.json .

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public

COPY --from=pruned-repo /app/start-web.sh .

RUN mkdir -p /app/apps/web/public/uploads/
RUN chown -R ${USER}:${USER} /app/apps/web/public/uploads/

CMD ["/bin/sh", "/app/start-web.sh"]
2 changes: 2 additions & 0 deletions apps/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const config = {
"@sora-vp/validators",
],

output: "standalone",

/** We already do linting and typechecking as separate tasks in CI */
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
Expand Down
43 changes: 43 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: "3.8"
services:
db:
image: mysql:latest
cap_add:
- SYS_NICE
restart: always
environment:
- MYSQL_DATABASE=sora
- MYSQL_USER=tingyun
- MYSQL_PASSWORD=majesticfoxian
- MYSQL_ROOT_PASSWORD=sillylookingcat
ports:
- '3306:3306'
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
volumes:
- db:/var/lib/mysql
- ./db/init.sql:/docker-entrypoint-initdb.d/init.sql

web:
container_name: sora_web
image: rmecha/sora-baseline-web:main
restart: always
depends_on:
db:
condition: service_healthy
environment:
DB_HOST: db
DB_NAME: sora
DB_USERNAME: tingyun
DB_PASSWORD: majesticfoxian
AUTH_SECRET: sdfjsklfjiuhr83uiwrew89323oriewf
ports:
- 0.0.0.0:3000:3000
volumes:
- web_uploads:/app/apps/web/public/uploads

volumes:
db:
web_uploads:
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"clean:workspaces": "turbo clean",
"db:push": "yarn workspace @sora-vp/db push",
"db:studio": "yarn workspace @sora-vp/db studio",
"db:generate": "yarn workspace @sora-vp/db generate",
"dev": "turbo dev --parallel",
"dev:web": "turbo run dev --filter @sora-vp/web",
"dev:processor": "turbo run dev --filter @sora-vp/processor",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"license": "MIT",
"scripts": {
"build": "tsc",
"type-build": "tsc",
"dev": "tsc --watch",
"clean": "rm -rf .turbo node_modules",
"format": "prettier --check . --ignore-path ../../.gitignore",
Expand Down
9 changes: 9 additions & 0 deletions packages/db-migrate/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import baseConfig from "@sora-vp/eslint-config/base";

/** @type {import('typescript-eslint').Config} */
export default [
{
ignores: ["dist/**"],
},
...baseConfig,
];
31 changes: 31 additions & 0 deletions packages/db-migrate/migrations/0000_confused_forgotten_one.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CREATE TABLE `sora_candidate` (
`id` int AUTO_INCREMENT NOT NULL,
`name` text NOT NULL,
`counter` int NOT NULL DEFAULT 0,
`image` varchar(100) NOT NULL,
CONSTRAINT `sora_candidate_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `sora_participant` (
`id` int AUTO_INCREMENT NOT NULL,
`name` text NOT NULL,
`sub_part` varchar(50) NOT NULL,
`qr_id` varchar(30),
`already_attended` boolean NOT NULL DEFAULT false,
`attended_at` timestamp,
`already_choosing` boolean NOT NULL DEFAULT false,
`choosing_at` timestamp,
CONSTRAINT `sora_participant_id` PRIMARY KEY(`id`),
CONSTRAINT `qr_id_unique_index` UNIQUE(`qr_id`)
);
--> statement-breakpoint
CREATE TABLE `sora_user` (
`id` int AUTO_INCREMENT NOT NULL,
`name` text NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`verified_at` timestamp,
`role` enum('admin','comittee'),
CONSTRAINT `sora_user_id` PRIMARY KEY(`id`),
CONSTRAINT `email_unique_index` UNIQUE(`email`)
);
Loading
Loading