From 66b21dabcd296c72da58ee3bb20425b17cd76687 Mon Sep 17 00:00:00 2001 From: aleidk Date: Fri, 20 Dec 2024 16:16:15 -0300 Subject: [PATCH] build: add docker build setup --- .dockerignore | 21 ++++++++++++++++ .forgejo/workflows/build-docker-image.yaml | 29 ++++++++++++++++++++++ .forgejo/workflows/create.yml | 20 --------------- .justfile | 3 +++ Dockerfile | 26 +++++++++++++++++++ entrypoint.sh | 5 ++++ 6 files changed, 84 insertions(+), 20 deletions(-) create mode 100644 .dockerignore create mode 100644 .forgejo/workflows/build-docker-image.yaml delete mode 100644 .forgejo/workflows/create.yml create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6a53ac5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,21 @@ +# ---> VirtualEnv +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +.Python +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +.venv +pip-selfcheck.json + +# ---> GPG +secring.* + +.env +Dockerfile +.forgejo +.git diff --git a/.forgejo/workflows/build-docker-image.yaml b/.forgejo/workflows/build-docker-image.yaml new file mode 100644 index 0000000..749c3cf --- /dev/null +++ b/.forgejo/workflows/build-docker-image.yaml @@ -0,0 +1,29 @@ +name: Publish image +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + create-docker-images: + runs-on: host + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: git.alecodes.page + username: ${{ vars.CONTAINER_REGISTRY_USER }} + password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: | + git.alecodes.page/alecodes/miniflux-archive:latest + git.alecodes.page/alecodes/miniflux-archive:${{ github.sha }} diff --git a/.forgejo/workflows/create.yml b/.forgejo/workflows/create.yml deleted file mode 100644 index 0c619c8..0000000 --- a/.forgejo/workflows/create.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Template migration - -# The workflow will run only when `use this template` is used -on: create - -jobs: - create: - runs-on: docker - - steps: - - name: "Check out the repo" - uses: "actions/checkout@v4" - - - name: "Update commit" - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: "chore: initial commit" - commit_options: "--amend" - push_options: "--force" - skip_fetch: true diff --git a/.justfile b/.justfile index 56b070a..644b56a 100644 --- a/.justfile +++ b/.justfile @@ -1,2 +1,5 @@ run: go run main.go run linkding --archive-starred + +docker-build: + docker build . --tag miniflux-archiver:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..55f951f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM golang:1.23-alpine AS builder + +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 ./main.go + +FROM alpine + +COPY --from=builder /usr/src/app/main /usr/bin/miniflux-archiver + +ENV MFA_CRON="* * * * *" + +WORKDIR /app + +COPY ./entrypoint.sh . + +ENTRYPOINT ["./entrypoint.sh"] + +RUN chmod +x entrypoint.sh /usr/bin/miniflux-archiver + +CMD ["--help"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..7d31953 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +echo "$MFA_CRON /usr/bin/miniflux-archiver $*" | crontab - + +crond -f -d 8