|
| 1 | +name: Test Reproducible Docker Build |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - 'Dockerfile' |
| 7 | + - '.github/workflows/test_reproducible_docker.yaml' |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + test-reproducible-build: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 # Important: full history for git log |
| 18 | + |
| 19 | + - name: Set up Docker Buildx |
| 20 | + uses: docker/setup-buildx-action@v3 |
| 21 | + |
| 22 | + - name: Build reproducible Docker image (first build) |
| 23 | + uses: docker/build-push-action@v5 |
| 24 | + with: |
| 25 | + context: . |
| 26 | + target: rbuilder-reproducible-runtime |
| 27 | + platforms: linux/amd64 |
| 28 | + push: false |
| 29 | + load: true |
| 30 | + tags: test-reproducible:build1 |
| 31 | + build-args: | |
| 32 | + RBUILDER_BIN=op-rbuilder |
| 33 | + FEATURES= |
| 34 | +
|
| 35 | + - name: Extract binary from first build |
| 36 | + run: | |
| 37 | + docker create --name temp1 test-reproducible:build1 |
| 38 | + docker cp temp1:/app/rbuilder build1 |
| 39 | + docker rm temp1 |
| 40 | + sha256sum build1 > build1.sha256 |
| 41 | + echo "Build 1 SHA256:" |
| 42 | + cat build1.sha256 |
| 43 | +
|
| 44 | + - name: Clean Docker build cache |
| 45 | + run: | |
| 46 | + docker builder prune -af |
| 47 | + docker system prune -af |
| 48 | +
|
| 49 | + - name: Build reproducible Docker image (second build) |
| 50 | + uses: docker/build-push-action@v5 |
| 51 | + with: |
| 52 | + context: . |
| 53 | + target: rbuilder-reproducible-runtime |
| 54 | + platforms: linux/amd64 |
| 55 | + push: false |
| 56 | + load: true |
| 57 | + tags: test-reproducible:build2 |
| 58 | + build-args: | |
| 59 | + RBUILDER_BIN=op-rbuilder |
| 60 | + FEATURES=optimism |
| 61 | +
|
| 62 | + - name: Extract binary from second build |
| 63 | + run: | |
| 64 | + docker create --name temp2 test-reproducible:build2 |
| 65 | + docker cp temp2:/app/rbuilder build2 |
| 66 | + docker rm temp2 |
| 67 | + sha256sum build2 > build2.sha256 |
| 68 | + echo "Build 2 SHA256:" |
| 69 | + cat build2.sha256 |
| 70 | +
|
| 71 | + - name: Compare builds |
| 72 | + run: | |
| 73 | + echo "=== Comparing SHA256 hashes ===" |
| 74 | + if diff build1.sha256 build2.sha256; then |
| 75 | + echo "✅ SUCCESS: Builds are reproducible!" |
| 76 | + else |
| 77 | + echo "❌ FAILURE: Builds are NOT reproducible" |
| 78 | + echo "Build 1:" && cat build1.sha256 |
| 79 | + echo "Build 2:" && cat build2.sha256 |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Test git log command in build stage |
| 84 | + uses: docker/build-push-action@v5 |
| 85 | + with: |
| 86 | + context: . |
| 87 | + target: rbuilder-reproducible # Build stage, not runtime |
| 88 | + platforms: linux/amd64 |
| 89 | + push: false |
| 90 | + load: true |
| 91 | + tags: test-reproducible:buildstage |
| 92 | + build-args: | |
| 93 | + RBUILDER_BIN=op-rbuilder |
| 94 | + FEATURES=optimism |
| 95 | +
|
| 96 | + - name: Verify git log works in container |
| 97 | + run: | |
| 98 | + echo "=== Testing git log command in build container ===" |
| 99 | + docker run --rm test-reproducible:buildstage sh -c "cd /app && git log -1 --pretty=%ct" |
| 100 | + if [ $? -eq 0 ]; then |
| 101 | + echo "✅ git log command works in container" |
| 102 | + else |
| 103 | + echo "❌ git log command failed in container" |
| 104 | + exit 1 |
| 105 | + fi |
0 commit comments