Skip to content

Commit

Permalink
docker compose support
Browse files Browse the repository at this point in the history
  • Loading branch information
skewb1k committed Nov 17, 2024
1 parent c690cda commit 39294d4
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.gitignore
.git
README.md
Makefile
.env.example
ROADMAP.md
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SERVER_PORT=
SERVER_HOST=
SERVER_UPDATES_INTERVAL=
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode
.env
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.23.2-alpine3.20 AS build

WORKDIR /app

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

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -o server ./cmd/server

FROM scratch

WORKDIR /app

COPY --from=build app/server .

ENTRYPOINT ["./server"]
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
gen-env-example:
sed 's/=.*/=/' .env > .env.example

up:
docker compose up

build:
docker compose build

run:
go run cmd/server/main.go
docker compose up --build

docker-clean:
docker compose down --remove-orphans
docker system prune -af
docker volume prune -f
docker network prune -f

.PHONY: run
.PHONY: gen-env-example up run build docker-clean
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func loadAppConfig() *app.AppConfig {
viper.BindPFlags(pflag.CommandLine)

// 3. Set up environment variables prefix and binding
viper.SetEnvPrefix("APP")
viper.SetEnvPrefix("SERVER")
viper.AutomaticEnv()

// 4. Set defaults (lowest priority)
Expand Down
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
server:
container_name: sharetube-server
build:
dockerfile: Dockerfile
env_file:
- .env
ports:
- ${SERVER_PORT}:${SERVER_PORT}
restart: unless-stopped
networks:
- sharetube

# nginx:
# image: nginx:latest
# container_name: nginx
# ports:
# - "80:80"
# - "443:443"
# volumes:
# - ./nginx.conf:/etc/nginx/nginx.conf
# - /etc/letsencrypt:/etc/letsencrypt
# - /var/www/certbot:/var/www/certbot
# depends_on:
# - app

networks:
sharetube:

0 comments on commit 39294d4

Please sign in to comment.