Skip to content

Commit

Permalink
Add Docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
Brawl345 committed Jan 12, 2024
1 parent 9e7f1f7 commit 86eb98d
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!handler/
!storage/
!go.mod
!go.sum
!main.go
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BOT_TOKEN=123456789:abcdefghijklmnopqrstuvxwyz
MYSQL_HOST=127.0.0.1
MYSQL_HOST=127.0.0.1 # Use 'db' for Docker
MYSQL_PORT=3306
MYSQL_USER=myuser
MYSQL_PASSWORD=mypassword
MYSQL_DB=mydb
MYSQL_DB=mydb
38 changes: 35 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
GOOS: [ windows, linux, darwin ]
GOARCH: [ amd64, 386, arm, arm64 ]
GOOS: [windows, linux, darwin]
GOARCH: [amd64, 386, arm, arm64]
exclude:
- GOOS: windows
GOARCH: arm
Expand All @@ -25,7 +25,7 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache
uses: actions/cache@v3
Expand Down Expand Up @@ -59,3 +59,35 @@ jobs:
path: dist/*
retention-days: 90

docker:
name: docker
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v4

- name: Build image
run: docker build . --file Dockerfile --tag $NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$NAME
# This changes all uppercase characters to lowercase.
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# This strips the git ref prefix from the version.
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# This strips the "v" prefix from the tag name.
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# This uses the Docker `latest` tag convention.
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.21 AS build-stage
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN CGO_ENABLED=0 GOOS=linux go build -o /tagesschau-eilbot

FROM gcr.io/distroless/base-debian12 AS release-stage
WORKDIR /app
COPY --from=build-stage /tagesschau-eilbot /app/tagesschau-eilbot
USER nonroot:nonroot
ENTRYPOINT ["/app/tagesschau-eilbot"]
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3.8'

name: tagesschau-eilbot
services:
bot:
# build: .
pull_policy: always
image: ghcr.io/brawl345/tagesschau-eilbot:latest
restart: always
env_file: .env

db:
image: mariadb:latest
restart: always
environment:
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DB}
MYSQL_RANDOM_ROOT_PASSWORD: true
ports:
- '33060:3306'
volumes:
- 'tagesschau-eilbot-db:/var/lib/mysql'
healthcheck:
test: ['CMD', 'healthcheck.sh', '--connect', '--innodb_initialized']
start_period: 1m
start_interval: 10s
interval: 1m
timeout: 5s
retries: 3

volumes:
tagesschau-eilbot-db:
name: tagesschau-eilbot-db
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

0 comments on commit 86eb98d

Please sign in to comment.