From a98f034f1e3a769b83456e05f9beaeffbdea6137 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Tue, 24 Sep 2024 17:06:18 -0400 Subject: [PATCH] feat: first version Signed-off-by: Michael Dawson --- .github/workflows/build-and-publish.yml | 68 +++++++++++++++++++++++++ container-build-info/Dockerfile | 37 ++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 .github/workflows/build-and-publish.yml create mode 100644 container-build-info/Dockerfile diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml new file mode 100644 index 0000000..3806ada --- /dev/null +++ b/.github/workflows/build-and-publish.yml @@ -0,0 +1,68 @@ +# +name: Build and publish the wasm builder container + +# Configures this workflow to run every time a change is pushed to the branch called `release`. +on: + push: + branches: ['main'] + paths: + - container-build-info/** + workflow_dispatch: + +# We push to the github registry with the image name that matches the repository +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# Run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Get Git commit timestamps + run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: "{{defaultContext}}:container-build-info" + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + env: + SOURCE_DATE_EPOCH: 0 + + # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)." + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + + diff --git a/container-build-info/Dockerfile b/container-build-info/Dockerfile new file mode 100644 index 0000000..6955490 --- /dev/null +++ b/container-build-info/Dockerfile @@ -0,0 +1,37 @@ +# Modify these to update to newer versions +FROM node:22-alpine3.19@sha256:3cb4748ed93c45cf4622c3382a5ce063af1fcbc5f3da6d2b669352ebace9f76d +ARG BINARYEN_VERSION=116 + +ARG UID=1000 +ARG GID=1000 + +# set SOURCE_DATE_EPOCH for reproduciability - https://reproducible-builds.org/docs/source-date-epoch/ +ENV SOURCE_DATE_EPOCH: 0 + +ENV ROOT_DIR /home/node +ENV METADATA_DIR $ROOT_DIR/metadata +RUN mkdir $METADATA_DIR +ENV WORKDIR_DIR $ROOT_DIR/build +RUN mkdir WORKDIR_DIR +WORKDIR $WORKDIR_DIR + +# Keep a copy of the Dockerfile used +COPY Dockerfile /home/node/metadata/Dockerfile + +# Install required system packages +RUN apk add -U clang lld wasi-sdk +RUN apk info -v >/home/node/metadata/apk-info + +# Install BINARYEN +RUN wget https://github.com/WebAssembly/binaryen/releases/download/version_$BINARYEN_VERSION/binaryen-version_$BINARYEN_VERSION-x86_64-linux.tar.gz && \ + tar -zxvf binaryen-version_$BINARYEN_VERSION-x86_64-linux.tar.gz binaryen-version_$BINARYEN_VERSION/bin/wasm-opt && \ + mv binaryen-version_$BINARYEN_VERSION/bin/wasm-opt ./ && \ + rm binaryen-version_$BINARYEN_VERSION-x86_64-linux.tar.gz && \ + rm -rf binaryen-version_$BINARYEN_VERSION && \ + chmod +x ./wasm-opt +ENV WASM_OPT=$WORKDIR_DIR/wasm-opt +RUN echo "Binaryen-version: $BINARYEN_VERSION" >$METADATA_DIR/binaryen-info +RUN echo "Binaryen-url: https://github.com/WebAssembly/binaryen/releases/download/version_$BINARYEN_VERSION/binaryen-version_$BINARYEN_VERSION-x86_64-linux.tar.gz" >>$METADATA_DIR/binaryen-info +RUN echo "Binaryen-binary: $WASM_OPT" >>$METADATA_DIR/binaryen-info + +USER node