From 481b99308f2de05b2348e4face3e153844d57f77 Mon Sep 17 00:00:00 2001 From: asonix Date: Thu, 8 Feb 2024 13:09:59 -0600 Subject: [PATCH] Initial commit --- .forgejo/workflows/publish.yaml | 178 ++++++++++++++++++++++++++++++++ Dockerfile | 20 ++++ install-docker.sh | 18 ++++ install-rust.sh | 19 ++++ install-zig.sh | 35 +++++++ 5 files changed, 270 insertions(+) create mode 100644 .forgejo/workflows/publish.yaml create mode 100644 Dockerfile create mode 100644 install-docker.sh create mode 100644 install-rust.sh create mode 100644 install-zig.sh diff --git a/.forgejo/workflows/publish.yaml b/.forgejo/workflows/publish.yaml new file mode 100644 index 0000000..c247924 --- /dev/null +++ b/.forgejo/workflows/publish.yaml @@ -0,0 +1,178 @@ +on: + push: + tags: + - 'v*.*.*' + + +env: + REGISTRY_IMAGE: asonix/actions-base-image + +jobs: + build: + runs-on: docker + container: + image: docker.io/node:20-bookworm + strategy: + matrix: + platform: + - amd64 + - arm64 + steps: + - + name: Checkout + uses: https://github.com/actions/checkout@v4 + - + name: Install Docker + run: | + apt-get update + apt-get install -y ca-certificates curl jq + install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc + chmod a+r /etc/apt/keyrings/docker.asc + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null + apt-get update + apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + - + name: Prepare Platform + run: | + platform=${{ matrix.info.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + shell: bash + - + name: Docker meta + id: meta + uses: https://github.com/docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + flavor: | + latest=false + suffix=-${{ matrix.info.artifact }} + tags: | + type=raw,value=latest,enable={{ is_default_branch }} + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=ref,event=branch + - + name: Set up QEMU + uses: https://github.com/docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: https://github.com/docker/setup-buildx-action@v3 + - + name: Docker login + uses: https://github.com/docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push ${{ matrix.info.platform }} docker image + id: build + uses: docker/build-push-action@v5 + with: + context: . + platforms: ${{ matrix.info.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + - + name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + echo "Created /tmp/digests/${digest#sha256:}" + shell: bash + - + name: Upload ${{ matrix.info.platform }} digest + uses: https://github.com/actions/upload-artifact@v3 + with: + name: digests + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + publish-docker: + runs-on: docker + container: + image: docker.io/node:20-bookworm + needs: [build] + steps: + - + name: Install Docker + run: | + apt-get update + apt-get install -y ca-certificates curl jq + install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc + chmod a+r /etc/apt/keyrings/docker.asc + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null + apt-get update + apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + - + name: Download digests + uses: https://github.com/actions/download-artifact@v3 + with: + name: digests + path: /tmp/digests + pattern: digests-* + merge-multiple: true + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Docker login + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Docker meta + id: meta + uses: https://github.com/docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + flavor: | + latest=false + tags: | + type=raw,value=latest,enable={{ is_default_branch }} + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=ref,event=branch + - + name: Create manifest list and push + working-directory: /tmp/digests + run: | + tags=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "${DOCKER_METADATA_OUTPUT_JSON}") + images=$(printf "${{ env.REGISTRY_IMAGE }}@sha256:%s " *) + echo "Running 'docker buildx imagetools create ${tags[@]} ${images[@]}'" + docker buildx imagetools create ${tags[@]} ${images[@]} + shell: bash + - + name: Inspect Image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} + + publish-forgejo: + needs: [build] + runs-on: docker + container: + image: node:20-bookworm + steps: + - uses: https://github.com/actions/download-artifact@v3 + with: + name: binaries + path: artifacts/ + merge-multiple: true + - uses: actions/forgejo-release@v1 + with: + direction: upload + token: ${{ secrets.GITHUB_TOKEN }} + release-dir: artifacts/ + prerelease: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..edc7d55 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM docker.io/node:20-bookworm + +RUN \ + mkdir -p /opt && \ + apt-get update && \ + apt-get install -y jq + +ENV \ + PATH=/opt/zig:/root/.cargo/bin:/root/.rustup/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin + +COPY --chmod=744 install-docker.sh /opt/install-docker.sh +RUN bash /opt/install-docker.sh + +COPY --chmod=744 install-zig.sh /opt/install-zig.sh +RUN bash /opt/install-zig.sh + +COPY --chmod=744 install-rust.sh /opt/install-rust.sh +RUN bash /opt/install-rust.sh + +CMD ["/usr/bin/bash"] diff --git a/install-docker.sh b/install-docker.sh new file mode 100644 index 0000000..6ad65dd --- /dev/null +++ b/install-docker.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -xe + +apt-get update +apt-get install -y ca-certificates curl +install -m 0755 -d /etc/apt/keyrings + +curl -fsSL 'https://download.docker.com/linux/debian/gpg' -o /etc/apt/keyrings/docker.asc +chmod a+r /etc/apt/keyrings/docker.asc +echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null + +apt-get update +apt-get install -y \ + docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin diff --git a/install-rust.sh b/install-rust.sh new file mode 100644 index 0000000..976974d --- /dev/null +++ b/install-rust.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -xe + +TOOLCHAIN=${1:-'stable'} + +mkdir -p /opt + +curl --proto '=https' --tlsv1.2 -sSfL 'https://sh.rustup.rs' -o /opt/rustup.sh +chmod +x /opt/rustup.sh +/opt/rustup.sh --profile minimal --default-toolchain $TOOLCHAIN -y +rm /opt/rustup.sh + +rustup component add clippy +rustup target add x86_64-unknown-linux-musl +rustup target add armv7-unknown-linux-musleabihf +rustup target add aarch64-unknown-linux-musl + +cargo install cargo-zigbuild diff --git a/install-zig.sh b/install-zig.sh new file mode 100644 index 0000000..156221b --- /dev/null +++ b/install-zig.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +set -xe + +VERSION=${1:-'0.11.0'} +DIR=${2:-'/opt'} +machine=$(uname -m) + +case $machine in + x86_64) + ARCH=x86_64 + ;; + + aarch64) + ARCH=aarch64 + ;; + + armv7l) + ARCH=armv7a + ;; + *) + echo "Invalid machine architecture $machine" + exit 1 +esac + +mkdir -p $DIR + +curl --proto '=https' --tlsv1.2 -sSfL \ + "https://ziglang.org/download/${VERSION}/zig-linux-${ARCH}-${VERSION}.tar.xz" \ + -o $DIR/zig.tar.xz + +tar -xJf $DIR/zig.tar.xz +rm $DIR/zig.tar.xz + +mv zig-linux-${ARCH}-${VERSION} $DIR/zig