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 13, 2024
1 parent e14e005 commit 1f6d7b6
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*
!config/
!handler/
!storage/
!go.mod
!go.sum
!main.go
!post.gohtml
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ADMIN_ID=1337
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
Expand Down
36 changes: 34 additions & 2 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 Down Expand Up @@ -68,3 +68,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 /rssbot

FROM gcr.io/distroless/static-debian12 AS release-stage
WORKDIR /app
COPY --from=build-stage /rssbot /app/rssbot
USER nonroot:nonroot
ENTRYPOINT ["/app/rssbot"]
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: rssbot
services:
bot:
build: .
pull_policy: always
# image: ghcr.io/brawl345/rssbot: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:
- 'rssbot-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:
rssbot-db:
name: rssbot-db
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down

0 comments on commit 1f6d7b6

Please sign in to comment.