Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/build-image-on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "Test build of image when Dockerfile is changed"

on:
push:
paths:
- "Dockerfile"
branches-ignore:
- main
pull_request:
paths:
- "Dockerfile"
workflow_dispatch:

env:
GHCR_REPO: ghcr.io/${{ github.repository_owner }}/ohttp-relay

jobs:
rebuild-container:
name: "Build image with cache"
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- ubuntu-24.04-arm
runs-on: ${{ matrix.os }}
steps:
- name: Prepare platform matrix for arm64
if: runner.arch == 'ARM64'
run: |
echo "PLATFORM=linux/arm64" >> $GITHUB_ENV
echo "DIGEST_NAME=arm64" >> $GITHUB_ENV
- name: Prepare platform matrix for amd64
if: runner.arch == 'X64'
run: |
echo "PLATFORM=linux/amd64" >> $GITHUB_ENV
echo "DIGEST_NAME=amd64" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.9.0
- name: Checkout repository
uses: actions/checkout@v4
- name: Test build of image
id: build
uses: docker/build-push-action@v6.13.0
with:
push: false
load: true
platforms: ${{ env.PLATFORM }}
tags: ohttp-relay:testing
cache-from: type=registry,ref=${{ env.GHCR_REPO }}:latest
- name: Test-run image
run: |
docker run --rm -e GATEWAY_ORIGIN=https://payjo.in ohttp-relay:testing &
PID=$!
sleep 30
kill -SIGINT $PID # this will return a non-zero exit code if the container dies early on
124 changes: 124 additions & 0 deletions .github/workflows/update-image-on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: "Update image when Dockerfile is changed"

on:
push:
branches:
- main
paths:
- "Dockerfile"
workflow_dispatch:

env:
GHCR_REPO: ghcr.io/${{ github.repository_owner }}/ohttp-relay

jobs:
build:
name: "Build container for multiple architectures and push by digest"
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- ubuntu-24.04-arm
runs-on: ${{ matrix.os }}
steps:
- name: Prepare platform matrix for arm64
if: runner.arch == 'ARM64'
run: |
echo "PLATFORM=linux/arm64" >> $GITHUB_ENV
echo "DIGEST_NAME=arm64" >> $GITHUB_ENV

- name: Prepare platform matrix for amd64
if: runner.arch == 'X64'
run: |
echo "PLATFORM=linux/amd64" >> $GITHUB_ENV
echo "DIGEST_NAME=amd64" >> $GITHUB_ENV

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR_REPO }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.9.0

- name: Login to GitHub Container Registry
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout repository
uses: actions/checkout@v4

- name: Build and and push by digest
uses: docker/build-push-action@v6.13.0
id: build
with:
outputs: type=image,"name=${{ env.GHCR_REPO }}",push-by-digest=true,name-canonical=true,push=true
platforms: ${{ env.PLATFORM }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.GHCR_REPO }}:latest

- name: Export digest
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"

- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.DIGEST_NAME }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1

merge:
name: "Merge digests and push with proper tags"
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true

- name: Login to GHCR
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.9.0

- name: Checkout repository
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR_REPO }}
tags: |
type=sha
type=raw,value=latest,enable={{is_default_branch}}

- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.GHCR_REPO }}@sha256:%s ' *)

- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.GHCR_REPO }}:${{ steps.meta.outputs.version }}
17 changes: 10 additions & 7 deletions ohttp-relay/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Stage 1: Building the binary
FROM nixos/nix:2.20.5 AS builder

# Copy our source and setup our working dir.
# Copy our source and setup our working directory
COPY . /tmp/build
WORKDIR /tmp/build

Expand All @@ -13,16 +13,19 @@ RUN nix \

# Copy the Nix store closure into a directory. The Nix store closure is the
# entire set of Nix store values that we need for our build.
RUN mkdir /tmp/nix-store-closure
RUN cp -R $(nix-store -qR result/) /tmp/nix-store-closure
RUN mkdir /tmp/nix-store-closure \
&& cp -R $(nix-store -qR result/) /tmp/nix-store-closure

# Stage 2: running ohttp-relay
# Final image is based on scratch. We copy a bunch of Nix dependencies
# but they're fully self-contained so we don't need Nix anymore.
FROM scratch
FROM scratch AS final

WORKDIR /ohttp-relay

# Copy /nix/store
# Copy necessary files from builder stage
COPY --from=builder /tmp/nix-store-closure /nix/store
COPY --from=builder /tmp/build/result /ohttp-relay
CMD ["/ohttp-relay/bin/ohttp-relay"]
COPY --from=builder /tmp/build/result/bin/ohttp-relay /bin/ohttp-relay

# Run ohttp-relay at start
CMD ["/bin/ohttp-relay"]
Loading