From 5e3543c39244e28324c42af8870f46d297522b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Sun, 21 Jan 2024 20:42:56 +0100 Subject: [PATCH] Add Dockerfile and build with GitHub Actions --- .github/workflows/docker-publish.yml | 32 ++++++++++++++++++++++++++++ .vscode/settings.json | 1 + Dockerfile | 12 +++++++++++ docker-compose.yml | 5 +++++ 4 files changed, 50 insertions(+) create mode 100644 .github/workflows/docker-publish.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..11b65fb --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,32 @@ +name: Test and Build Docker Image + +on: + push: + pull_request: + workflow_dispatch: + schedule: + - cron: "0 0 * * *" +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + if: github.event_name != 'pull_request' + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: | + ghcr.io/thelovinator1/anewdawn:latest diff --git a/.vscode/settings.json b/.vscode/settings.json index ee5c4c5..e436c5f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "cSpell.words": [ + "anewdawn", "bwmarrin", "discordgo", "godotenv", diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ff0a351 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM golang:1.21-alpine + +WORKDIR /usr/src/app + +# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change +COPY go.mod go.sum ./ +RUN go mod download && go mod verify + +COPY . . +RUN go build -v -o /usr/local/bin/app ./... + +CMD ["app"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5798f84 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,5 @@ +services: + anewdawn: + image: ghcr.io/thelovinator1/anewdawn:master + container_name: anewdawn + restart: unless-stopped