Skip to content

Commit

Permalink
improve container building
Browse files Browse the repository at this point in the history
  • Loading branch information
jon4h committed May 16, 2021
1 parent ba312f0 commit 3640370
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 8 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# meta
.idea
.vscode
.github

# data
data/database.db
config/config.yml
.env

# other
notes.txt
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
.vscode

# data
database.db
data/database.db
config/config.yml
.env

# other
notes.txt
Expand Down
19 changes: 13 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
FROM golang:alpine
FROM golang:alpine as builder
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN apk add --no-cache gcc musl-dev
RUN go build -o cornix-tv-forwarder .
RUN adduser -S -D -H -h /app appuser
USER appuser
CMD ["./cornix-tv-forwarder"]
# add build dependencies
RUN apk add --no-cache gcc musl-dev upx
# build the binary
RUN go build -o cornix-tv-channel -ldflags="-s" .
# compress the binary
RUN upx -9 -k cornix-tv-channel

# build the runtime image (apline because of cgo dependecies)
FROM alpine:latest
COPY --from=builder /app/cornix-tv-channel .
EXPOSE 3000
ENTRYPOINT [ "./cornix-tv-channel" ]
16 changes: 16 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:alpine as builder
RUN mkdir /app
ADD . /app/
WORKDIR /app
# add build dependencies
RUN apk add --no-cache gcc musl-dev upx
# build the binary
RUN go build -o cornix-tv-channel -ldflags="-s" .
# compress the binary
RUN upx -9 -k cornix-tv-channel

# build an empty container
FROM alpine:latest
COPY --from=builder /app/cornix-tv-channel .
EXPOSE 3000
ENTRYPOINT [ "./cornix-tv-channel" ]
2 changes: 1 addition & 1 deletion config/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Connect(config *Config) {
gormConfig.QueryFields = true
}

DB, err = gorm.Open(sqlite.Open("database.db"), gormConfig)
DB, err = gorm.Open(sqlite.Open("data/database.db"), gormConfig)
if err != nil {
panic(fmt.Sprintf("[database][init] error: %s", err))
}
Expand Down
Empty file added database.db
Empty file.
16 changes: 16 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
version: '3.7'
services:
cornix-tv-channel:
build:
context: .
dockerfile: Dockerfile.dev
restart: unless-stopped
hostname: cornix-tv-channel
container_name: cornix-tv-channel
volumes:
- ./data:/data
env_file:
- .env
ports:
- 3000:3000
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
version: '3.7'
services:
cornix-tv-channel:
image: jon4hz/cornix-tv-channel
restart: unless-stopped
hostname: cornix-tv-channel
container_name: cornix-tv-channel
volumes:
- ./data:/data
env_file:
- .env
networks:
traefik_proxy:

networks:
traefik_proxy:
external: true

0 comments on commit 3640370

Please sign in to comment.