Skip to content

Commit

Permalink
feat(backend): ref #4 開発環境の用意
Browse files Browse the repository at this point in the history
  • Loading branch information
oribe1115 committed Jun 9, 2021
1 parent 4a85e50 commit e937f62
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 0 deletions.
5 changes: 5 additions & 0 deletions development/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
up:
docker-compose -f docker-compose.yml up --build

down:
docker-compose -f docker-compose.yml down
17 changes: 17 additions & 0 deletions development/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:1.16.5-alpine3.13

WORKDIR /development
COPY development/backend/air.toml .

WORKDIR /go/src/isucondition

ENV DOCKERIZE_VERSION v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& go get -u github.com/cosmtrek/air

COPY webapp/go/go.mod .
# COPY webapp/go/go.sum .

RUN go mod download
53 changes: 53 additions & 0 deletions development/backend/air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "/go/src/isucondition"
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o isucondition ."
# Binary file yields from `cmd`.
bin = "isucondition"
# Customize binary.
full_bin = "APP_ENV=dev APP_USER=air ./isucondition"
# Watch these filename extensions.
include_ext = ["go"]
# Ignore these filename extensions or directories.
exclude_dir = []
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# Exclude specific regular expressions.
exclude_regex = []
# Exclude unchanged files.
exclude_unchanged = true
# Follow symlink for directories
follow_symlink = true
# This log file places in your tmp_dir.
log = "air.log"
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false
# Delay after sending Interrupt signal
kill_delay = 500 # ms

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true
35 changes: 35 additions & 0 deletions development/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "3.8"

services:
backend:
build:
context: ..
dockerfile: development/backend/Dockerfile
environment:
MYSQL_HOST: mysql-backend
MYSQL_PORT: 3306
MYSQL_DATABASE: isucondition
MYSQL_USER: isucon
MYSQL_PASSWORD: isucon
entrypoint: dockerize -wait tcp://mysql-backend:3306 -timeout 60s
command: air -c /development/air.toml
ports:
- "3000:3000"
volumes:
- "../webapp/go:/go/src/isucondition"
depends_on:
- mysql-backend

mysql-backend:
image: mysql:8.0.25
restart: always
environment:
MYSQL_DATABASE: isucondition
MYSQL_USER: isucon
MYSQL_PASSWORD: isucon
MYSQL_ROOT_PASSWORD: root
expose:
- "3306"
ports:
- "3306:3306"

1 change: 1 addition & 0 deletions webapp/go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
isucondition
3 changes: 3 additions & 0 deletions webapp/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/isucon/isucon11-qualify/isucondition

go 1.16
13 changes: 13 additions & 0 deletions webapp/go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"time"
)

func main() {
for {
fmt.Println("Hello World")
time.Sleep(time.Second * 10)
}
}

0 comments on commit e937f62

Please sign in to comment.