diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..00d6366 --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,48 @@ +name: 'File-uploader-crystal CI' + +on: + # workflow_dispatch: + # inputs: {} + schedule: + - cron: '0 7 * * 0' + push: + branches: + - "master" + +jobs: + build: + runs-on: runner + + steps: + - uses: https://code.forgejo.org/actions/checkout@v2 + + - uses: https://code.forgejo.org/docker/setup-buildx-action@v3 + name: Setup Docker BuildX system + + - name: Login to Docker Container Registry + uses: https://code.forgejo.org/docker/login-action@v3.1.0 + with: + registry: git.nadeko.net + username: ${{ secrets.USERNAME }} + password: ${{ secrets.TOKEN }} + + - name: Docker meta + id: meta + uses: https://github.com/docker/metadata-action@v5 + with: + images: git.nadeko.net/fijxu/file-uploader-crystal + tags: | + type=sha,format=short,prefix={{date 'YYYY.MM.DD'}}-,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} + + - uses: https://code.forgejo.org/docker/build-push-action@v5 + name: Build images + with: + context: . + file: docker/Dockerfile + tags: ${{ steps.meta.outputs.tags }} + platforms: linux/amd64 + push: true + build-args: | + "release=1" + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..192474a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# Based on https://github.com/iv-org/invidious/blob/master/docker/Dockerfile +FROM crystallang/crystal:1.13.2-alpine AS builder + +RUN apk add --no-cache sqlite-static yaml-static + +ARG release + +WORKDIR /file-uploader-crystal +COPY ./shard.yml ./shard.yml +COPY ./shard.lock ./shard.lock +RUN shards install --production + +COPY ./src/ ./src/ +# TODO: .git folder is required for building – this is destructive. +# See definition of CURRENT_BRANCH, CURRENT_COMMIT and CURRENT_VERSION. +COPY ./.git/ ./.git/ + +RUN crystal build ./src/file-uploader-crystal.cr \ + --release \ + --static --warnings all + +RUN apk add --no-cache tini +FROM alpine:3.18 +WORKDIR /file-uploader-crystal +RUN addgroup -g 1000 -S file-uploader-crystal && \ + adduser -u 1000 -S file-uploader-crystal -G file-uploader-crystal +COPY --chown=file-uploader-crystal ./config/config.* ./config/ +RUN mv -n config/config.example.yml config/config.yml +COPY --from=builder /file-uploader-crystal/file-uploader-crystal . +RUN chmod o+rX -R ./config + +EXPOSE 8080 +USER invidious +ENTRYPOINT ["/sbin/tini", "--"] +CMD [ "/invidious/file-uploader" ] diff --git a/shard.yml b/shard.yml index a800b4f..e1c6f69 100644 --- a/shard.yml +++ b/shard.yml @@ -1,4 +1,4 @@ -name: file-uploader +name: file-uploader-crystal version: 0.8.7 authors: @@ -6,7 +6,7 @@ authors: targets: file-uploader: - main: src/file-uploader.cr + main: src/file-uploader-crystal.cr dependencies: kemal: diff --git a/src/file-uploader.cr b/src/file-uploader-crystal.cr similarity index 100% rename from src/file-uploader.cr rename to src/file-uploader-crystal.cr