Skip to content

Commit 86eb98d

Browse files
committed
Add Docker support
1 parent 9e7f1f7 commit 86eb98d

File tree

6 files changed

+89
-8
lines changed

6 files changed

+89
-8
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
!handler/
3+
!storage/
4+
!go.mod
5+
!go.sum
6+
!main.go

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BOT_TOKEN=123456789:abcdefghijklmnopqrstuvxwyz
2-
MYSQL_HOST=127.0.0.1
2+
MYSQL_HOST=127.0.0.1 # Use 'db' for Docker
33
MYSQL_PORT=3306
44
MYSQL_USER=myuser
55
MYSQL_PASSWORD=mypassword
6-
MYSQL_DB=mydb
6+
MYSQL_DB=mydb

.github/workflows/build.yml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
GOOS: [ windows, linux, darwin ]
17-
GOARCH: [ amd64, 386, arm, arm64 ]
16+
GOOS: [windows, linux, darwin]
17+
GOARCH: [amd64, 386, arm, arm64]
1818
exclude:
1919
- GOOS: windows
2020
GOARCH: arm
@@ -25,7 +25,7 @@ jobs:
2525

2626
steps:
2727
- name: Checkout repo
28-
uses: actions/checkout@v3
28+
uses: actions/checkout@v4
2929

3030
- name: Cache
3131
uses: actions/cache@v3
@@ -59,3 +59,35 @@ jobs:
5959
path: dist/*
6060
retention-days: 90
6161

62+
docker:
63+
name: docker
64+
runs-on: ubuntu-latest
65+
permissions:
66+
packages: write
67+
contents: read
68+
69+
steps:
70+
- uses: actions/checkout@v4
71+
72+
- name: Build image
73+
run: docker build . --file Dockerfile --tag $NAME --label "runnumber=${GITHUB_RUN_ID}"
74+
75+
- name: Log in to registry
76+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
77+
78+
- name: Push image
79+
run: |
80+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$NAME
81+
82+
# This changes all uppercase characters to lowercase.
83+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
84+
# This strips the git ref prefix from the version.
85+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
86+
# This strips the "v" prefix from the tag name.
87+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
88+
# This uses the Docker `latest` tag convention.
89+
[ "$VERSION" == "master" ] && VERSION=latest
90+
echo IMAGE_ID=$IMAGE_ID
91+
echo VERSION=$VERSION
92+
docker tag $NAME $IMAGE_ID:$VERSION
93+
docker push $IMAGE_ID:$VERSION

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM golang:1.21 AS build-stage
2+
WORKDIR /app
3+
COPY go.mod go.sum ./
4+
RUN go mod download
5+
COPY . ./
6+
RUN CGO_ENABLED=0 GOOS=linux go build -o /tagesschau-eilbot
7+
8+
FROM gcr.io/distroless/base-debian12 AS release-stage
9+
WORKDIR /app
10+
COPY --from=build-stage /tagesschau-eilbot /app/tagesschau-eilbot
11+
USER nonroot:nonroot
12+
ENTRYPOINT ["/app/tagesschau-eilbot"]

docker-compose.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: '3.8'
2+
3+
name: tagesschau-eilbot
4+
services:
5+
bot:
6+
# build: .
7+
pull_policy: always
8+
image: ghcr.io/brawl345/tagesschau-eilbot:latest
9+
restart: always
10+
env_file: .env
11+
12+
db:
13+
image: mariadb:latest
14+
restart: always
15+
environment:
16+
MYSQL_USER: ${MYSQL_USER}
17+
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
18+
MYSQL_DATABASE: ${MYSQL_DB}
19+
MYSQL_RANDOM_ROOT_PASSWORD: true
20+
ports:
21+
- '33060:3306'
22+
volumes:
23+
- 'tagesschau-eilbot-db:/var/lib/mysql'
24+
healthcheck:
25+
test: ['CMD', 'healthcheck.sh', '--connect', '--innodb_initialized']
26+
start_period: 1m
27+
start_interval: 10s
28+
interval: 1m
29+
timeout: 5s
30+
retries: 3
31+
32+
volumes:
33+
tagesschau-eilbot-db:
34+
name: tagesschau-eilbot-db

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)