From e8d155d3132570e0d298cd0ef45b270f2591e783 Mon Sep 17 00:00:00 2001 From: TMH Date: Wed, 28 Feb 2024 16:58:28 +0100 Subject: [PATCH] add Dockerfile, Docker-Compose example and build and push Image for GitHub --- .github/workflows/docker-compose.yml.example | 14 ++++++++ .github/workflows/publish.yml | 35 ++++++++++++++++++++ Dockerfile | 18 ++++++++++ 3 files changed, 67 insertions(+) create mode 100644 .github/workflows/docker-compose.yml.example create mode 100644 .github/workflows/publish.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker-compose.yml.example b/.github/workflows/docker-compose.yml.example new file mode 100644 index 0000000..c3593af --- /dev/null +++ b/.github/workflows/docker-compose.yml.example @@ -0,0 +1,14 @@ +version: '3.7' +services: + porygon: + image: ghcr.io/roundaboutluke/porygon:main + container_name: porygon + restart: unless-stopped + volumes: + # mount the config.toml file and persistent storage for MessageIDs + - ${PWD}/config.toml:/porygon/config.toml + - ${PWD}/messageIDs.json:/porygon/messageIDs.json # file must be created before the first start the container (touch messageIDs.json) + # optional if you want to use your own template + # comment if not needed + - ${PWD}/current.override.json:/porygon/templates/current.override.json + diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..2215d08 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,35 @@ +name: publish + +on: [push] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..62fe0d0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +# Build image +FROM golang:1.21-alpine as build + +WORKDIR /go/src/app +COPY go.mod go.sum ./ +RUN if [ ! -f vendor/modules.txt ]; then go mod download; fi + +COPY . . +RUN CGO_ENABLED=0 go build -o /go/bin/porygon + +# Now copy it into our base image. +FROM gcr.io/distroless/static-debian12 as runner +COPY --from=build /go/bin/porygon /porygon/ +COPY default.toml /porygon/ +COPY /templates /porygon/templates + +WORKDIR /porygon +CMD ["./porygon"] \ No newline at end of file