Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
spectrapulse committed Apr 30, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
0 parents commit 0d023a0
Showing 4 changed files with 211 additions and 0 deletions.
195 changes: 195 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
name: Build binaries and container images

on:
push:
workflow_dispatch:
schedule: [ cron: '0 4 * * *' ]

permissions:
packages: write
contents: write

jobs:
build:
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc
CC_aarch64_unknown_linux_musl: aarch64-linux-gnu-gcc
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER: arm-linux-gnueabihf-gcc
CC_armv7_unknown_linux_musleabihf: arm-linux-gnueabihf-gcc
outputs:
commit: ${{ steps.meta.outputs.commit }}
version: ${{ steps.meta.outputs.version }}
continue: ${{ steps.meta.outputs.continue }}
strategy:
fail-fast: true
matrix:
arch: [ amd64, arm32v7, arm64v8 ]
include:
- arch: amd64
target: x86_64-unknown-linux-musl
platform: linux/amd64
- arch: arm32v7
target: armv7-unknown-linux-musleabihf
platform: linux/arm/v7
- arch: arm64v8
target: aarch64-unknown-linux-musl
platform: linux/arm64
steps:
- uses: actions/checkout@v4

- run: git clone --depth=1 https://github.com/redlib-org/redlib

- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
# This action's built-in cache setup expects the Cargo.toml
# to be at a specific unchangable location which won't work for
# our setup. So we'll setup our own caching.
cache: false
target: ${{ matrix.target }}

- id: meta
run: |
cd redlib
echo "continue=$(diff -u ../.last_commit <(git rev-parse --short HEAD) > /dev/null 2>&1 && echo false || echo true)" >> $GITHUB_OUTPUT
echo "version=$(cargo metadata --format-version 1 --no-deps | jq .packages[0].version -r | sed 's/^/v/')" >> $GITHUB_OUTPUT
echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- if: ${{ ( steps.meta.outputs.continue == 'true' ) && ( matrix.arch == 'amd64' ) }}
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends musl-tools
- if: ${{ ( steps.meta.outputs.continue == 'true' ) && ( matrix.arch == 'arm32v7' ) }}
run: |
sudo apt-get update
sudo apt-get install -y gcc-arm-linux-gnueabihf musl-tools
- if: ${{ ( steps.meta.outputs.continue == 'true' ) && ( matrix.arch == 'arm64v8' ) }}
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu musl-tools
- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: actions/cache/restore@v4
id: pre-cache-restore
with:
path: |
/home/runner/.cargo
/home/runner/work/redlib/redlib/redlib/target
key: pre-cache-matrix-${{ matrix.arch }}-${{ hashFiles('./redlib/Cargo.toml') }}

- if: ${{ steps.meta.outputs.continue == 'true' }}
run: |
cd redlib
cargo build --release --target ${{ matrix.target }}
- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: actions/cache/save@v4
id: pre-cache-save
with:
path: |
/home/runner/.cargo
/home/runner/work/redlib/redlib/redlib/target
key: ${{ steps.pre-cache-restore.outputs.cache-primary-key }}

- if: ${{ steps.meta.outputs.continue == 'true' }}
run: tar czfv redlib-${{ matrix.target }}.tar.gz -C redlib/target/${{ matrix.target }}/release/ redlib

- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: redlib-${{ matrix.target }}.tar.gz

- if: ${{ steps.meta.outputs.continue == 'true' }}
run: cp -v redlib/target/${{ matrix.target }}/release/redlib ./redlib-bin

- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: docker/setup-qemu-action@v3

- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: docker/setup-buildx-action@v3

- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: docker/metadata-action@v5
id: image-meta
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ matrix.arch }}-${{ steps.meta.outputs.version }},enable={{is_default_branch}}
type=raw,value=${{ matrix.arch }}-${{ steps.meta.outputs.commit }},enable={{is_default_branch}}
type=raw,value=${{ matrix.arch }},enable={{is_default_branch}}
- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: actions/cache/restore@v4
id: build-cache-restore
with:
path: .docker_cache
key: build-cache-matrix-${{ matrix.arch }}-${{ hashFiles('./Dockerfile') }}

- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: docker/build-push-action@v5
with:
push: true
context: .
cache-to: type=local,dest=.docker_cache/
cache-from: type=local,src=.docker_cache/
platforms: ${{ matrix.platform }}
tags: ${{ steps.image-meta.outputs.tags }}
labels: ${{ steps.image-meta.outputs.labels }}

- if: ${{ steps.meta.outputs.continue == 'true' }}
uses: actions/cache/save@v4
id: build-cache-save
with:
path: .docker_cache
key: ${{ steps.build-cache-restore.outputs.cache-primary-key }}

merge:
if: ${{ needs.build.outputs.continue == 'true' }}
runs-on: ubuntu-latest
needs: [ build ]
env:
IMAGE: ghcr.io/${{ github.repository }}
COMMIT: ${{ needs.build.outputs.commit }}
VERSION: ${{ needs.build.outputs.version }}
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }

- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- run: |
docker buildx imagetools create \
--tag ${IMAGE}:${COMMIT} ${IMAGE}:{amd64,arm32v7,arm64v8}-${COMMIT}
docker buildx imagetools create \
--tag ${IMAGE}:${VERSION} ${IMAGE}:{amd64,arm32v7,arm64v8}-${VERSION}
docker buildx imagetools create \
--tag ${IMAGE}:latest ${IMAGE}:{amd64,arm32v7,arm64v8}
- run: |
OLD=$(cat .last_commit)
NEW=${COMMIT}
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
echo "${NEW}" > .last_commit
git add .last_commit
git commit -m "Update .last_commit" -m "${OLD} >> ${NEW}"
git status
git push -u origin master
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
redlib/
.docker_cache/
.env
1 change: 1 addition & 0 deletions .last_commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1337
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM alpine:3.19

RUN adduser --home /nonexistent --no-create-home --disabled-password redlib
USER redlib

COPY ./redlib-bin /usr/local/bin/redlib

EXPOSE 8080

HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1

ENTRYPOINT [ "/usr/local/bin/redlib" ]

0 comments on commit 0d023a0

Please sign in to comment.