Skip to content

Commit

Permalink
Merge pull request #7 from claustra01/infra/docker
Browse files Browse the repository at this point in the history
インフラ構築
  • Loading branch information
claustra01 authored Mar 28, 2024
2 parents 8473117 + fae73f4 commit 1b6b36d
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .env.local.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ACR_HOST=
ACR_USER=
ACR_PASSWORD=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env.local
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
include .env.local

.PHONY: up down push

up:
docker compose up -d --build

down:
docker-compose down

push:
docker login $(ACR_HOST) -u $(ACR_USER) -p $(ACR_PASSWORD)
docker build -t bot ./bot
docker build -t web ./web
docker tag bot $(ACR_HOST)/bot:latest
docker tag web $(ACR_HOST)/web:latest
docker push $(ACR_HOST)/bot:latest
docker push $(ACR_HOST)/web:latest
23 changes: 23 additions & 0 deletions bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.22-alpine AS build
ENV TZ=Asia/Tokyo

WORKDIR /opt/app

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
RUN go build -o ./calendeye

#------------------------------------------------------------
FROM gcr.io/distroless/base:nonroot AS runner
ENV TZ=Asia/Tokyo
ENV GOENV=production
ENV PORT=80

COPY --from=build /opt/app/calendeye /bin/calendeye

EXPOSE ${PORT}
USER nonroot
ENTRYPOINT [ "/bin/calendeye" ]
8 changes: 5 additions & 3 deletions bot/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (

func main() {
// Load environment variables from .env file
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
if os.Getenv("GOENV") != "production" {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
}

// Get channel secret and channel token from environment variables
Expand Down
20 changes: 20 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3'
services:

bot:
build:
context: ./bot
dockerfile: Dockerfile
env_file:
- ./bot/.env
ports:
- 5000:80

web:
build:
context: ./web
dockerfile: Dockerfile
env_file:
- ./web/.env
ports:
- 5173:80
23 changes: 23 additions & 0 deletions web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:20-alpine AS build
ENV TZ=Asia/Tokyo

WORKDIR /opt/app

COPY package.json .
COPY package-lock.json .
RUN npm install

COPY . .
RUN npm run build

#------------------------------------------------------------
FROM nginx:latest
ENV TZ=Asia/Tokyo

WORKDIR /etc/nginx/html

RUN rm -rf /usr/share/nginx/html/*
COPY --from=build /opt/app/dist/ /usr/share/nginx/html/

EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]
3 changes: 3 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"@vitejs/plugin-react": "4.2.1",
"typescript": "5.4.3",
"vite": "5.2.6"
},
"volta": {
"node": "20.12.0"
}
}

0 comments on commit 1b6b36d

Please sign in to comment.