Skip to content

Commit

Permalink
Merge pull request #477 from traPtitech/refactor/docker
Browse files Browse the repository at this point in the history
refactor/docker
  • Loading branch information
ras0q authored Oct 25, 2023
2 parents 47068f3 + 95d41d8 commit 9a19f7b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 126 deletions.
42 changes: 0 additions & 42 deletions .air.toml

This file was deleted.

17 changes: 9 additions & 8 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
.git
.gitignore
.gitmodules
_development/
.git/
.github/
docs/
.dockerignore
.DS_Store
_development
docs
tmp
.env.example
.gitignore
.golangci.yml
compose.yml
Dockerfile
README.md

52 changes: 35 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
# syntax=docker/dockerfile:1

# for production
#
# build stage
#
FROM golang:1-alpine as builder

FROM golang:1-alpine as server-build

WORKDIR /github.com/traPtitech/knoq
WORKDIR /app

COPY go.mod go.sum ./
ENV GO111MODULE=on
RUN go mod download
COPY ./ ./
ENV GOOS=linux
ENV GOARCH=amd64
ENV GOCACHE=/root/.cache/go-build
ENV GOMODCACHE=/go/pkg/mod

RUN go build -o knoq
COPY go.mod go.sum ./
RUN --mount=type=cache,target=${GOCACHE} \
--mount=type=cache,target=${GOMODCACHE} \
go mod download

FROM alpine:latest
COPY ./ ./
RUN --mount=type=cache,target=${GOCACHE} \
--mount=type=cache,target=${GOMODCACHE} \
go build -o /app/knoq

# static files
RUN mkdir -p /app/web \
&& apk add --no-cache curl \
&& curl -L -Ss https://github.com/traPtitech/knoQ-UI/releases/latest/download/dist.tar.gz \
| tar zxv -C /app/web
# Google Calendar API needs service.json
RUN touch /app/service.json

#
# runtime stage
#
FROM gcr.io/distroless/static-debian11:latest

WORKDIR /app

RUN apk --update add tzdata \
&& cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime \
&& apk add --update ca-certificates \
&& update-ca-certificates \
&& rm -rf /var/cache/apk/*

COPY --from=server-build /github.com/traPtitech/knoq/knoq ./
# COPY --from=builder /app/knoq /app/web/ /app/service.json /app/
COPY --from=builder /app/knoq /app/
COPY --from=builder /app/web/ /app/web/
COPY --from=builder /app/service.json /app/

ARG knoq_version=dev
ARG knoq_revision=local
ENV KNOQ_VERSION=${knoq_version}
ENV KNOQ_REVISION=${knoq_revision}

ENTRYPOINT ./knoq
CMD ["/app/knoq"]
22 changes: 0 additions & 22 deletions Dockerfile.dev

This file was deleted.

50 changes: 14 additions & 36 deletions docker-compose.yml → compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
version: "3"

networks:
default:


services:
knoq:
app:
build:
context: .
dockerfile: ./Dockerfile.dev
container_name: knoq_development_app
dockerfile: ./Dockerfile
container_name: knoq_app
environment:
TZ: Asia/Tokyo
MARIADB_USERNAME: root
Expand All @@ -29,26 +25,19 @@ services:
KNOQ_VERSION: ${KNOQ_VERSION:-dev}
DEVELOPMENT: true
GORM_LOG_LEVEL: info
volumes:
- ./main.go:/srv/knoq/main.go
- ./router:/srv/knoq/router
- ./utils:/srv/knoq/utils
- ./migration:/srv/knoq/migration
- ./domain:/srv/knoq/domain
- ./infra:/srv/knoq/infra
- ./presentation:/srv/knoq/presentation
- ./repository:/srv/knoq/repository
ports:
- "6006:3000"
- "${APP_PORT:-3000}:3000"
depends_on:
mysql:
condition: service_healthy
networks:
- default
develop:
watch:
- action: rebuild
path: ./

mysql:
db:
image: mariadb:10.6.4
container_name: knoq_development_mysql
container_name: knoq_db
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: knoQ
Expand All @@ -62,23 +51,12 @@ services:
interval: 1s
timeout: 10s
retries: 60
networks:
- default

phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: knoq_development_phpmyadmin
volumes:
- "./_development/phpmyadmin:/sessions"
adminer:
image: adminer
container_name: knoq_adminer
ports:
- 8000:80
environment:
- PMA_ARBITRARY=1
- PMA_HOST=mysql
- PMA_USER=root
- PMA_PASSWORD=password
- "8000:8080"
depends_on:
mysql:
condition: service_healthy
networks:
- default
10 changes: 9 additions & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ docker compose up

を実行すると以下の環境が起動します

- knoQのホットリロード環境([cosmtrek/air](https://github.com/cosmtrek/air))
- knoQアプリ (フロントエンドを含みます)
- <http://localhost:6006>
- DB(MariaDB)
- DB接続クライアント(PHPMyAdmin)
- <http://localhost:8000>

> **Info**
> 代わりに以下のコマンドを実行することで、ソースコードの変更を検知して自動で再起動させることができます
> 参考: [Compose Watch](https://docs.docker.com/compose/file-watch/)
>
> ```bash
> docker compose watch
> ```
## ディレクトリ構造
2023/08現在でディレクトリ構造は以下のようになっています
Expand Down

0 comments on commit 9a19f7b

Please sign in to comment.