|
| 1 | +name: Reproducible Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'tutorial/01a-reproducible-builds/**' |
| 7 | + pull_request: |
| 8 | + paths: |
| 9 | + - 'tutorial/01a-reproducible-builds/**' |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +env: |
| 13 | + REGISTRY: ghcr.io |
| 14 | + IMAGE_NAME: ${{ github.repository }}/tutorial-01a-oracle |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + packages: write |
| 22 | + defaults: |
| 23 | + run: |
| 24 | + working-directory: tutorial/01a-reproducible-builds |
| 25 | + |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Set up Docker Buildx |
| 30 | + uses: docker/setup-buildx-action@v3 |
| 31 | + |
| 32 | + - name: Install skopeo |
| 33 | + run: sudo apt-get update && sudo apt-get install -y skopeo |
| 34 | + |
| 35 | + - name: Build reproducible image |
| 36 | + run: | |
| 37 | + docker buildx create --name repro-builder --driver docker-container || true |
| 38 | + docker buildx build \ |
| 39 | + --builder repro-builder \ |
| 40 | + --build-arg SOURCE_DATE_EPOCH=0 \ |
| 41 | + --no-cache \ |
| 42 | + --output type=oci,dest=image.tar,rewrite-timestamp=true \ |
| 43 | + . |
| 44 | +
|
| 45 | + - name: Compute and display hash |
| 46 | + id: hash |
| 47 | + run: | |
| 48 | + HASH=$(sha256sum image.tar | awk '{print $1}') |
| 49 | + DIGEST=$(skopeo inspect oci-archive:image.tar | jq -r .Digest) |
| 50 | + echo "image_hash=$HASH" >> $GITHUB_OUTPUT |
| 51 | + echo "image_digest=$DIGEST" >> $GITHUB_OUTPUT |
| 52 | + echo "## Reproducible Build Results" >> $GITHUB_STEP_SUMMARY |
| 53 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 54 | + echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY |
| 55 | + echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY |
| 56 | + echo "| **Image Hash** | \`$HASH\` |" >> $GITHUB_STEP_SUMMARY |
| 57 | + echo "| **Image Digest** | \`$DIGEST\` |" >> $GITHUB_STEP_SUMMARY |
| 58 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 59 | + echo "Compare with your local build:" >> $GITHUB_STEP_SUMMARY |
| 60 | + echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY |
| 61 | + echo "cd tutorial/01a-reproducible-builds && ./build-reproducible.sh" >> $GITHUB_STEP_SUMMARY |
| 62 | + echo "cat build-manifest.json" >> $GITHUB_STEP_SUMMARY |
| 63 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 64 | +
|
| 65 | + - name: Verify against committed manifest |
| 66 | + run: | |
| 67 | + if [[ -f build-manifest.json ]]; then |
| 68 | + EXPECTED=$(jq -r .image_hash build-manifest.json) |
| 69 | + ACTUAL="${{ steps.hash.outputs.image_hash }}" |
| 70 | + echo "Expected: $EXPECTED" |
| 71 | + echo "Actual: $ACTUAL" |
| 72 | + if [[ "$EXPECTED" == "$ACTUAL" ]]; then |
| 73 | + echo "✓ Build matches committed manifest" |
| 74 | + else |
| 75 | + echo "✗ Build differs from committed manifest" |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | + else |
| 79 | + echo "No build-manifest.json found - skipping verification" |
| 80 | + fi |
| 81 | +
|
| 82 | + - name: Upload OCI image |
| 83 | + uses: actions/upload-artifact@v4 |
| 84 | + with: |
| 85 | + name: reproducible-image |
| 86 | + path: tutorial/01a-reproducible-builds/image.tar |
| 87 | + retention-days: 7 |
| 88 | + |
| 89 | + - name: Login to GHCR |
| 90 | + if: github.event_name != 'pull_request' |
| 91 | + uses: docker/login-action@v3 |
| 92 | + with: |
| 93 | + registry: ${{ env.REGISTRY }} |
| 94 | + username: ${{ github.actor }} |
| 95 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + |
| 97 | + - name: Push to GHCR |
| 98 | + if: github.event_name != 'pull_request' |
| 99 | + run: | |
| 100 | + IMAGE_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}" |
| 101 | + skopeo copy oci-archive:image.tar docker://$IMAGE_TAG |
| 102 | + echo "Pushed: $IMAGE_TAG" >> $GITHUB_STEP_SUMMARY |
| 103 | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 104 | + LATEST_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" |
| 105 | + skopeo copy oci-archive:image.tar docker://$LATEST_TAG |
| 106 | + echo "Pushed: $LATEST_TAG" >> $GITHUB_STEP_SUMMARY |
| 107 | + fi |
0 commit comments