diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5130919 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +# Files +LICENSE +README.md + +# Folders +.git/ +.gitea/ +content/ +data/ +deployments/ +docker/ +scripts/ diff --git a/.gitea/workflows/docker.yaml b/.gitea/workflows/docker.yaml new file mode 100644 index 0000000..8331d3b --- /dev/null +++ b/.gitea/workflows/docker.yaml @@ -0,0 +1,63 @@ +name: Docker Build and Push + +on: + workflow_dispatch: + push: + branches: + - 'main' + tags: + - '*' + release: + types: [ published ] + +env: + GITEA_CONTAINER_REG: gitea.nerthus.nl + DOCKER_IMAGE_NAME: orbits-server + +jobs: + docker_build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + fail-fast: false + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to Gitea container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.GITEA_CONTAINER_REG }} + username: ${{ gitea.repository_owner }} + password: ${{ secrets.GITEA_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: linux/amd64,linux/arm64 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract Docker metadata from environment + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.GITEA_CONTAINER_REG }}/daanselen/${{ env.DOCKER_IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=sha,format=short,prefix= + + - name: Build and export Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./docker/Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 diff --git a/docker/Dockerfile b/docker/Dockerfile index 473a0f4..f772a73 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -0,0 +1,19 @@ +FROM docker.io/golang:1.26-trixie AS build + +RUN mkdir /app +COPY . /app + +WORKDIR /app +RUN go mod tidy \ + && mkdir /app/bin \ + && go build -o /app/bin/orbits cmd/server/main.go + +FROM docker.io/debian:trixie-slim AS runtime + +RUN mkdir -p /app /data/config /data/content +COPY --from=build /app/bin/orbits /app/bin/orbits + +ENV CONTENT_DIR=/data/content \ + DATA_DIR=/data/config + +CMD ["/app/bin/orbits"]