Skip to content

Commit

Permalink
add docker compose file
Browse files Browse the repository at this point in the history
  • Loading branch information
falconluca committed Dec 24, 2021
1 parent 2c06613 commit 1b02edc
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.dbdata

/sql

README.md
Makefile
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.17-alpine
WORKDIR /app

ARG TARGETARCH
ARG TARGETOS

ENV GOPROXY=https://goproxy.cn
ENV GO111MODULE=on
COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download

COPY api/ api/
COPY cmd/ cmd/
COPY internal/ internal/
RUN CGO_ENABLED=0 GOARCH=$TARGETARCH GOOS=$TARGETOS go build -a -o server ./cmd/server/

COPY config/ config/
EXPOSE 50051
ENTRYPOINT ["./server"]
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ protoc:

.PHONY: wire
wire:
wire ./cmd/server
wire ./cmd/server

.PHONY: docker-build
docker-build:
docker build -t shaohsiung/memo:latest -f ./Dockerfile .
2 changes: 1 addition & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
grpc:
port: :50051
dsn: root:root@tcp(127.0.0.1:3306)/memo?charset=utf8mb4&parseTime=True&loc=Local
dsn: root:root@tcp(mysql:3306)/memo?charset=utf8mb4&parseTime=True&loc=Local
25 changes: 25 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.1"
services:
server:
restart: always
build:
context: .
dockerfile: Dockerfile
ports:
- "50051:50051"
depends_on:
- mysql
mysql:
image: "mysql:5.7"
platform: "linux/x86_64"
environment:
MYSQL_DATABASE: memo
MYSQL_ROOT_PASSWORD: root
volumes:
- .dbdata:/var/lib/mysql:rw
# https://gist.github.com/onjin/2dd3cc52ef79069de1faa2dfd456c945#gistcomment-2163519
- ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql
- ./mysql_custom.cnf:/etc/mysql/conf.d/custom.cnf
ports:
- "3306:3306"
restart: always
4 changes: 4 additions & 0 deletions mysql_custom.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[mysqld]
character-set-server = utf8
collation-server = utf8_unicode_ci
skip-character-set-client-handshake
File renamed without changes.

0 comments on commit 1b02edc

Please sign in to comment.