|
| 1 | +# Copyright (C) 2025 Siemens |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | +# |
| 5 | +# Derived from the https://github.com/siemens/kas docker-init action |
| 6 | + |
| 7 | +name: docker-init |
| 8 | + |
| 9 | +inputs: |
| 10 | + deploy-user: |
| 11 | + required: true |
| 12 | + deploy-token: |
| 13 | + required: true |
| 14 | + |
| 15 | +runs: |
| 16 | + using: composite |
| 17 | + steps: |
| 18 | + - name: Set up QEMU |
| 19 | + shell: bash |
| 20 | + env: |
| 21 | + QEMU_USER_STATIC_PACKAGE: qemu-user-static_7.2+dfsg-7+deb12u12_amd64.deb |
| 22 | + REPO_DATE: 20250130T084806Z |
| 23 | + PACKAGE_SHA256: 1a2696081c1f30d464f79fd300196822397c77f05440ea9ce6dc8e9658b595ec |
| 24 | + run: | |
| 25 | + # temporarily use Debian qemu-user-static until Ubuntu fixes theirs |
| 26 | + wget -q http://snapshot.debian.org/archive/debian/${REPO_DATE}/pool/main/q/qemu/${QEMU_USER_STATIC_PACKAGE} |
| 27 | + echo "${PACKAGE_SHA256} ${QEMU_USER_STATIC_PACKAGE}" | sha256sum -c |
| 28 | + sudo dpkg -i ${QEMU_USER_STATIC_PACKAGE} |
| 29 | +
|
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + with: |
| 33 | + driver-opts: image=moby/buildkit:v0.16.0 |
| 34 | + |
| 35 | + - name: Login to ghcr.io |
| 36 | + uses: docker/login-action@v3 |
| 37 | + with: |
| 38 | + registry: ghcr.io |
| 39 | + username: ${{ inputs.deploy-user }} |
| 40 | + password: ${{ inputs.deploy-token }} |
| 41 | + |
| 42 | + - name: Set SOURCE_DATE_EPOCH |
| 43 | + run: | |
| 44 | + echo "SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV |
| 45 | + shell: bash |
| 46 | + |
| 47 | + - name: Determine Debian tag |
| 48 | + run: | |
| 49 | + COMMIT_DATE=$(date -d @$(git log -1 --pretty=%ct) +%Y%m%d) |
| 50 | + DEBIAN_RELEASE=$(grep -m 1 'ARG DEBIAN_TAG=' Dockerfile | sed 's/.*DEBIAN_TAG=\(.*\)-.*/\1/') |
| 51 | + echo "DEBIAN_TAG=$(podman search --list-tags docker.io/debian --limit 1000000000 | \ |
| 52 | + grep "$DEBIAN_RELEASE-.*-slim" | sort -r | sed 's/.*[ ]\+//' | \ |
| 53 | + ./scripts/lower-bound.py $DEBIAN_RELEASE-$COMMIT_DATE-slim )" \ |
| 54 | + >> $GITHUB_ENV |
| 55 | + shell: bash |
| 56 | + |
| 57 | + - name: Prepare repository for COPY-in |
| 58 | + run: | |
| 59 | + git clone . /home/runner/debsbom-clone |
| 60 | + shell: bash |
| 61 | + |
| 62 | + - name: Define image metadata |
| 63 | + run: | |
| 64 | + echo "IMAGE_DESCRIPTION=debsbom generates (Software Bill of Materials) for distributions based on Debian" >> $GITHUB_ENV |
| 65 | + # make image metadata reproducible (also for image re-builders) |
| 66 | + echo "IMAGE_COMMIT_DATE=$(date -d @$(git log -1 --pretty=%ct) --iso-8601=seconds)" >> $GITHUB_ENV |
| 67 | + echo "IMAGE_OFFICIAL_URL=https://github.com/siemens/debsbom" >> $GITHUB_ENV |
| 68 | + shell: bash |
| 69 | + |
| 70 | + - name: Extract metadata |
| 71 | + id: meta |
| 72 | + uses: docker/metadata-action@v5 |
| 73 | + with: |
| 74 | + annotations: | |
| 75 | + org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }} |
| 76 | + org.opencontainers.image.licenses=MIT |
| 77 | + org.opencontainers.image.created=${{ env.IMAGE_COMMIT_DATE }} |
| 78 | + org.opencontainers.image.source=${{ env.IMAGE_OFFICIAL_URL }} |
| 79 | + org.opencontainers.image.url=${{ env.IMAGE_OFFICIAL_URL }} |
| 80 | + env: |
| 81 | + DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index |
| 82 | + |
| 83 | + - name: Cache apt |
| 84 | + id: cache-apt |
| 85 | + uses: actions/cache@v4 |
| 86 | + with: |
| 87 | + path: | |
| 88 | + var-cache-apt |
| 89 | + var-lib-apt |
| 90 | + key: cache-apt-${{ env.DEBIAN_TAG }}-${{ inputs.image-name }} |
| 91 | + |
| 92 | + - name: Inject cache into docker |
| 93 | + uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de #v3.1.2 |
| 94 | + with: |
| 95 | + cache-map: | |
| 96 | + { |
| 97 | + "var-cache-apt": "/var/cache/apt", |
| 98 | + "var-lib-apt": "/var/lib/apt" |
| 99 | + } |
| 100 | + skip-extraction: ${{ steps.cache.outputs.cache-hit }} |
0 commit comments