Skip to content

Commit 1b13300

Browse files
authored
Merge pull request #229 from lunakv/build-docker-images
Docker setup improvements
2 parents c8ca12b + 69c28a6 commit 1b13300

File tree

4 files changed

+74
-6
lines changed

4 files changed

+74
-6
lines changed

.github/workflows/docker-build.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Create and publish a Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
build-and-push-image:
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Log in to the container registry
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ${{ env.REGISTRY }}
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Extract metadata for Docker
32+
id: meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
36+
tags: |
37+
type=edge
38+
type=sha
39+
40+
- name: Build and push Docker image
41+
uses: docker/build-push-action@v5
42+
with:
43+
context: .
44+
push: true
45+
tags: ${{ steps.meta.output.tags }}
46+
labels: ${{ steps.meta.output.labels }}
47+

Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
FROM golang:1
1+
# Build stage
2+
FROM golang:1 AS builder
23
WORKDIR /go/src/app
34

4-
COPY . .
5+
COPY go.mod go.sum ./
6+
RUN go mod download
57

6-
RUN go install -v
8+
COPY *.go ./
9+
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fryatog
710

8-
CMD ["fryatog"]
11+
# Final stage
12+
FROM alpine:latest
13+
WORKDIR /app
14+
# config.json is expected to be added as a mount
15+
COPY short_names.json ./
16+
COPY --from=builder /fryatog ./fryatog
17+
CMD ["./fryatog"]

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
fryatog:
3+
build: .
4+
volumes:
5+
- type: bind
6+
source: ./config.json
7+
target: /app/config.json
8+
read_only: true
9+

utils.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,14 @@ func cappedMin(a, b, c int) int {
212212
}
213213

214214
func readConfig() configuration {
215-
file, _ := os.Open(configFile)
215+
file, err := os.Open(configFile)
216+
if err != nil {
217+
panic(err)
218+
}
216219
defer file.Close()
217220
decoder := json.NewDecoder(file)
218221
conf := configuration{}
219-
err := decoder.Decode(&conf)
222+
err = decoder.Decode(&conf)
220223
if err != nil {
221224
panic(err)
222225
}

0 commit comments

Comments
 (0)