Skip to content

Commit 5c7c057

Browse files
committedFeb 14, 2025
feat: docker support
Also removes old, unused Fly.io config
1 parent 8d1dbfd commit 5c7c057

12 files changed

+103
-156
lines changed
 

‎.dockerignore

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
config.toml
2-
heimdallr
3-
heimdallr.exe
4-
heimdallr.db
5-
.env
6-
Dockerfile
7-
.git
8-
.gitignore
9-
README.md
10-
LICENSE
11-
.dockerignore
1+
*
2+
!commands
3+
!components
4+
!config
5+
!globals
6+
!listeners
7+
!model
8+
!scheduled_tasks
9+
!task
10+
!utils
11+
!go.mod
12+
!go.sum
13+
!main.go
14+
!rm_commands.go
15+
!start.sh
16+
!litestream.yml

‎.github/workflows/build-image.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# WARNING: The build tag uses github.run_number which is a unique counter for
2+
# this workflow. Renaming, moving, or deleting this workflow file will reset the
3+
# run number. Please do not change the workflow filename or its identity without
4+
# coordinating with the team, as a reset can cause previously higher build
5+
# numbers to be replaced with lower ones.
6+
7+
name: Build and Push Docker Image to GHCR
8+
9+
on:
10+
push:
11+
branches:
12+
- main
13+
14+
concurrency:
15+
group: build-and-push
16+
cancel-in-progress: false
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
22+
permissions:
23+
contents: read
24+
packages: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Login to GitHub Container Registry
34+
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
35+
36+
- name: Build and push image
37+
uses: docker/build-push-action@v6
38+
with:
39+
context: .
40+
push: true
41+
tags: |
42+
ghcr.io/nllcommunity/heimdallr:${{ github.sha }}
43+
ghcr.io/nllcommunity/heimdallr:${{ github.run_number }}
44+
ghcr.io/nllcommunity/heimdallr:latest
45+
labels: |
46+
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
47+
org.opencontainers.image.revision=${{ github.sha }}

‎.github/workflows/deploy_prod.yml

-15
This file was deleted.

‎.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
},
1313
"[markdown]": {
1414
"editor.rulers": []
15-
}
15+
},
16+
"go.formatTool": "goimports"
1617
}

‎Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM golang:1.24 AS builder
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY go.mod go.sum ./
6+
7+
RUN go mod download
8+
9+
COPY . .
10+
11+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags "-s -w" -o heimdallr .
12+
13+
FROM alpine:3.21
14+
15+
WORKDIR /usr/src/app
16+
17+
RUN mkdir -p /var/lib/heimdallr
18+
ENV HEIMDALLR_BOT_DB=/var/lib/heimdallr/heimdallr.db
19+
VOLUME /var/lib/heimdallr
20+
21+
RUN apk add --no-cache ca-certificates fuse3 sqlite tini
22+
23+
COPY --from=litestream/litestream:0.3 /usr/local/bin/litestream /bin/litestream
24+
COPY --from=builder /usr/src/app/heimdallr /usr/src/app/bin/heimdallr
25+
COPY --from=builder /usr/src/app/litestream.yml /usr/src/app/start.sh ./
26+
27+
ENTRYPOINT ["/sbin/tini", "--"]
28+
CMD ["./start.sh"]

‎_fly/Dockerfile

-17
This file was deleted.

‎_fly/litefs.yml

-46
This file was deleted.

‎_fly/litestream.production.yml

-9
This file was deleted.

‎_fly/litestream.test.yml

-9
This file was deleted.

‎fly.production.toml

-19
This file was deleted.

‎fly.toml

-24
This file was deleted.

‎start.sh

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
START_COMMAND=./bin/heimdallr
44

55
set -e
66
set -u
7-
set -x
7+
8+
# If DB_REPLICA_URL is not set, start without replication
9+
if [ -z "${DB_REPLICA_URL:-}" ]; then
10+
echo "Starting without replication"
11+
exec "${START_COMMAND}"
12+
fi
813

914
litestream version
10-
echo "DB_REPLICA_URL=${DB_REPLICA_URL}"
15+
echo "DB_REPLICA_URL=${DB_REPLICA_URL:-}"
1116

12-
readonly DB_PATH='heimdallr.db'
17+
readonly DB_PATH="${HEIMDALLR_BOT_DB:-heimdallr.db}"
1318
export DB_PATH
1419

15-
if [[ -f "$DB_PATH" ]]; then
20+
if [ -f "$DB_PATH" ]; then
1621
echo "Existing database is $(stat -c %s "${DB_PATH}") bytes"
1722
else
1823
echo "Restoring database from replica"

0 commit comments

Comments
 (0)