Skip to content

Commit

Permalink
Merge pull request #794 from NUTFes/develop
Browse files Browse the repository at this point in the history
イメージビルドの簡略化
  • Loading branch information
Kubosaka authored Jun 20, 2024
2 parents c68d7a0 + c8cd132 commit c41799a
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 20 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ down:
seed:
docker compose run --rm api go mod tidy
docker compose run --rm api go run /app/tools/seeds/teacher_seeds.go
deploy:
docker compose -f docker-compose.prod.yml build
docker compose -f docker-compose.prod.yml up -d
local-deploy:
docker compose -f docker-compose.local-prod.yml build
docker compose -f docker-compose.local-prod.yml up

29 changes: 13 additions & 16 deletions api/prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
FROM golang:latest

# Build用 コンテナ
FROM golang:latest AS builder
WORKDIR /app
COPY . /app
ENV CGO_ENABLED=0 \
GOOS=linux
RUN go mod tidy
RUN go build -o ./main ./main.go

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y locales \
&& locale-gen ja_JP.UTF-8 \
&& echo "export LANG=ja_JP.UTF-8" >> ~/.bashrc

RUN export LANG=C.UTF-8
RUN export LANGUAGE=en_US:

ENV CGO_ENABLED=0
ENV GOOS=linux
#ENV GOARCH=amd64


# 本番用 軽量 Debian
FROM gcr.io/distroless/base-debian11:nonroot AS runner
LABEL org.opencontainers.image.source="https://github.com/NUTFes/FinanSu"
COPY --from=builder --chown=nonroot /app/main .
USER nonroot
EXPOSE 1323
CMD ["./main"]
51 changes: 51 additions & 0 deletions docker-compose.local-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
services:
db:
image: mysql:8.0
container_name: "nutfes-finansu-db"
volumes:
- ./mysql/db:/docker-entrypoint-initdb.d # 初期データ
- ./my.cnf:/etc/mysql/conf.d/my.cnf
environment:
MYSQL_DATABASE: finansu_db
MYSQL_USER: finansu
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: root
TZ: "Asia/Tokyo"
ports:
- "3306:3306"
restart: always

minio:
image: minio/minio:latest
ports:
- "9000:9000"
- "9001:9001"
volumes:
- ./tmp/minio/data:/data
command: "server /data --console-address :9001"
environment:
MINIO_ROOT_USER: user
MINIO_ROOT_PASSWORD: password

view:
build:
context: ./view
dockerfile: local-prod.Dockerfile
container_name: "nutfes-finansu-view"
command: "npm run start"
ports: ["3000:3000"]
depends_on: ["api"]

api:
build:
context: ./api
dockerfile: prod.Dockerfile
container_name: "nutfes-finansu-api"
env_file: ["./finansu.env"]
ports: ["1323:1323"]
environment:
ENV: "develop"
RESET_PASSWORD_URL: "https://finansu.nutfes.net/reset_password"
depends_on:
db:
condition: service_started
12 changes: 8 additions & 4 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@ services:
command: tunnel run

view:
build: "./view"
build:
context: ./view
dockerfile: prod.Dockerfile
container_name: "nutfes-finansu-view"
volumes: ["./view:/app"]
command: "npm run start"
ports: ["3000:3000"]
environment:
NEXT_PUBLIC_APP_ENV: "production"
NEXT_PUBLIC_ENDPOINT: minio
NEXT_PUBLIC_PORT: 9000
NEXT_PUBLIC_BUCKET_NAME: finansu
NEXT_PUBLIC_MINIO_ENDPONT: http://localhost:9000
depends_on: ["api"]

api:
build:
context: ./api
dockerfile: prod.Dockerfile
container_name: "nutfes-finansu-api"
volumes: ["./api:/app"]
command: "go run main.go"
env_file: ["./finansu.env"]
ports: ["1323:1323"]
environment:
ENV: "production"
RESET_PASSWORD_URL: "https://finansu.nutfes.net/reset_password"
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ services:
NEXT_PUBLIC_PORT: 9000
NEXT_PUBLIC_BUCKET_NAME: finansu
NEXT_PUBLIC_MINIO_ENDPONT: http://localhost:9000
RECOIL_DUPLICATE_ATOM_KEY_CHECKING_ENABLED: false
tty: true

api:
Expand Down
9 changes: 9 additions & 0 deletions view/local-prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:20.14
WORKDIR /app/next-project
COPY ./next-project /app/next-project

ENV NODE_ENV production
ENV NEXT_PUBLIC_APP_ENV develop

RUN npm install --production
RUN npm run build
9 changes: 9 additions & 0 deletions view/prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:20.14
WORKDIR /app/next-project
COPY ./next-project /app/next-project

ENV NODE_ENV production
ENV NEXT_PUBLIC_APP_ENV production

RUN npm install --production
RUN npm run build

0 comments on commit c41799a

Please sign in to comment.