From 1a08ebd59e727dd70ed279c7e6225edbea226a65 Mon Sep 17 00:00:00 2001 From: Seth For Privacy <40500387+sethforprivacy@users.noreply.github.com> Date: Tue, 7 May 2024 12:54:59 -0400 Subject: [PATCH] Improve Dockerfile and add Github Actions builds --- .github/workflows/build-image-on-push.yml | 56 +++++++++++++++ .github/workflows/update-base-image.yml | 48 +++++++++++++ .github/workflows/update-image-on-push.yml | 69 +++++++++++++++++++ .github/workflows/update-image-on-release.yml | 68 ++++++++++++++++++ Dockerfile | 2 +- 5 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build-image-on-push.yml create mode 100644 .github/workflows/update-base-image.yml create mode 100644 .github/workflows/update-image-on-push.yml create mode 100644 .github/workflows/update-image-on-release.yml diff --git a/.github/workflows/build-image-on-push.yml b/.github/workflows/build-image-on-push.yml new file mode 100644 index 000000000..7504850ca --- /dev/null +++ b/.github/workflows/build-image-on-push.yml @@ -0,0 +1,56 @@ +name: "Test build of image when Dockerfile is changed" + +on: + push: + paths: + - 'Dockerfile' + branches-ignore: + - master + pull_request: + paths: + - 'Dockerfile' + workflow_dispatch: + +jobs: + rebuild-container: + name: "Build image with cache" + runs-on: ubuntu-latest + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + with: + platforms: linux/arm64 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.3.0 + - + name: Checkout repository + uses: actions/checkout@v4 + - + name: Build x86_64 image + id: docker_build_amd64 + uses: docker/build-push-action@v5.3.0 + with: + push: false + load: true + platforms: linux/amd64 + tags: utreexod:amd64 + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/utreexod:latest + - + name: Test-run x86_64 image + run: | + docker run --rm utreexod:amd64 & + PID=$! + sleep 5 + kill -SIGINT $PID # this will return a non-zero exit code if the container dies early on + - + name: Build ARMv8 image + id: docker_build_arm64 + uses: docker/build-push-action@v5.3.0 + with: + push: false + load: true + platforms: linux/arm64 + tags: utreexod:arm64 + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/utreexod:latest diff --git a/.github/workflows/update-base-image.yml b/.github/workflows/update-base-image.yml new file mode 100644 index 000000000..c1b994ee7 --- /dev/null +++ b/.github/workflows/update-base-image.yml @@ -0,0 +1,48 @@ +name: "Update image and push to Github Packages and Docker Hub weekly" + +on: + schedule: + - cron: "0 12 * * 1" # Run every Monday at noon. + workflow_dispatch: + +jobs: + rebuild-container: + name: "Rebuild Container with the latest base image" + runs-on: ubuntu-latest + steps: + - + name: Prepare outputs + id: prep + run: | + echo "::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')" + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + with: + platforms: linux/arm64 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.3.0 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v3.1.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Checkout repository + uses: actions/checkout@v4 + - + name: Build and push to Docker Hub and GitHub Packages Docker Registry + id: docker_build + uses: docker/build-push-action@v5.3.0 + with: + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ghcr.io/${{ github.repository_owner }}/utreexod:latest + labels: | + org.opencontainers.image.source=${{ github.event.repository.html_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} diff --git a/.github/workflows/update-image-on-push.yml b/.github/workflows/update-image-on-push.yml new file mode 100644 index 000000000..f42494508 --- /dev/null +++ b/.github/workflows/update-image-on-push.yml @@ -0,0 +1,69 @@ +name: "Update image when Dockerfile is changed" + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + rebuild-container: + name: "Rebuild Container with the latest base image" + runs-on: ubuntu-latest + steps: + - + name: Prepare outputs + id: prep + run: | + echo "::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')" + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + with: + platforms: linux/arm64 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.3.0 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v3.1.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Checkout repository + uses: actions/checkout@v4 + - + name: Build x86_64 image + id: docker_build_amd64 + uses: docker/build-push-action@v5.3.0 + with: + push: false + load: true + platforms: linux/amd64 + tags: utreexod:amd64 + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/utreexod:latest + cache-to: type=inline + - + name: Test-run x86_64 image + run: | + docker run --rm utreexod:amd64 & + PID=$! + sleep 5 + kill -SIGINT $PID # this will return a non-zero exit code if the container dies early on + - + name: Build and push to Docker Hub and GitHub Packages Docker Registry + uses: docker/build-push-action@v5.3.0 + id: docker_build_push + with: + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ghcr.io/${{ github.repository_owner }}/utreexod:latest + labels: | + org.opencontainers.image.source=${{ github.event.repository.html_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/utreexod:latest + cache-to: type=inline diff --git a/.github/workflows/update-image-on-release.yml b/.github/workflows/update-image-on-release.yml new file mode 100644 index 000000000..9be7f2f87 --- /dev/null +++ b/.github/workflows/update-image-on-release.yml @@ -0,0 +1,68 @@ +name: "Update image when a release is published" + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + rebuild-container: + name: "Rebuild Container with the latest base image" + runs-on: ubuntu-latest + steps: + - + name: Prepare outputs + id: prep + run: | + echo "::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')" + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + with: + platforms: linux/arm64 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.3.0 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v3.1.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Checkout repository + uses: actions/checkout@v4 + - + name: Build x86_64 image + id: docker_build_amd64 + uses: docker/build-push-action@v5.3.0 + with: + push: false + load: true + platforms: linux/amd64 + tags: utreexod:amd64 + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/utreexod:latest + cache-to: type=inline + - + name: Test-run x86_64 image + run: | + docker run --rm utreexod:amd64 & + PID=$! + sleep 5 + kill -SIGINT $PID # this will return a non-zero exit code if the container dies early on + - + name: Build and push to Docker Hub and GitHub Packages Docker Registry + uses: docker/build-push-action@v5.3.0 + id: docker_build_push + with: + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ghcr.io/${{ github.repository_owner }}/utreexod:${{ github.ref_name }} + labels: | + org.opencontainers.image.source=${{ github.event.repository.html_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/utreexod:latest + cache-to: type=inline diff --git a/Dockerfile b/Dockerfile index 5a3d755b5..3326b1020 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN go install -v . ./cmd/... FROM ${ARCH:+${ARCH}/}alpine:${VER_ALPINE} -COPY --from=build-container /go/bin /bin +COPY --from=build-container /go/bin/utreexod /bin VOLUME ["/root/.utreexod"]