diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 56aae36..89bdde4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,119 +8,12 @@ on: jobs: build: runs-on: ubuntu-latest + steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' - - - name: Set env variables - run: | - echo "GITHUB_DATE=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV - echo "GITHUB_SHA=${{ github.sha }}" >> $GITHUB_ENV - - - name: Get latest Webapp release version - run: | - WEBAPP_RELEASE=$(curl -sX GET "https://api.github.com/repos/netbootxyz/webapp/releases/latest" | jq -r '. | .tag_name') - echo "WEBAPP_RELEASE=${WEBAPP_RELEASE}" >> $GITHUB_ENV - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Login to the GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ secrets.GHCR_USER }} - password: ${{ secrets.GHCR_TOKEN }} - - - name: Determine version numbers - id: version_check - continue-on-error: true - run: | - tag=latest - IMAGE=netbootxyz/netbootxyz - TOKEN=$(curl -sX GET \ - "https://ghcr.io/token?scope=repository%3Anetbootxyz%2Fnetbootxyz%3Apull" \ - | jq -r '.token') - MULTIDIGEST=$(curl -s \ - --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ - --header "Authorization: Bearer ${TOKEN}" \ - "https://ghcr.io/v2/${IMAGE}/manifests/${tag}" \ - | jq -r 'first(.manifests[].digest)') - DIGEST=$(curl -s \ - --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ - --header "Authorization: Bearer ${TOKEN}" \ - "https://ghcr.io/v2/${IMAGE}/manifests/${MULTIDIGEST}" \ - | jq -r '.config.digest') - IMAGE_INFO=$(curl -sL \ - --header "Authorization: Bearer ${TOKEN}" \ - "https://ghcr.io/v2/${IMAGE}/blobs/${DIGEST}" \ - | jq -r '.config') - IMAGE_RELEASE=$(echo ${IMAGE_INFO} | jq -r '.Labels.build_version' | awk '{print $3}') - IMAGE_VERSION=$(echo ${IMAGE_RELEASE} | awk -F'-nbxyz' '{print $1}') - NB_RELEASE_NUMBER=$(echo ${IMAGE_RELEASE} | awk -F'-nbxyz' '{print $2}') - TAG_SHA=$(git rev-list -n 1 ${IMAGE_RELEASE}) - if [ -z "${MULTIDIGEST}" ] || [ "${MULTIDIGEST}" == "null" ]; then - echo "**** No existing container build found, assuming first build ****" - VERSION_TAG=${WEBAPP_RELEASE}-nbxyz1 - echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV - elif [ "${WEBAPP_RELEASE}" == "${IMAGE_VERSION}" ]; then - echo "**** Version ${WEBAPP_RELEASE} unchanged, checking if there is anything to build..." - if [ "${TAG_SHA}" == "${GITHUB_SHA}" ]; then - echo "**** Nothing to do, exiting build... **** " - exit 1 - else - echo "**** Changes found... incrementing build number version... ****" - NB_RELEASE_NUMBER=$((NB_RELEASE_NUMBER + 1)) - VERSION_TAG=${IMAGE_VERSION}-nbxyz${NB_RELEASE_NUMBER} - echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV - fi - else - echo "**** New version ${WEBAPP_RELEASE} found; old version was ${IMAGE_VERSION}. Generating new webapp release... ****" - VERSION_TAG=${WEBAPP_RELEASE}-nbxyz1 - echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV - fi - - - name: Docker meta - if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success' - id: meta - uses: docker/metadata-action@v4 - with: - images: netbootxyz/netbootxyz - labels: | - maintainer=antonym - org.opencontainers.image.created=${{ env.GITHUB_DATE }} - org.opencontainers.image.authors=netboot.xyz - org.opencontainers.image.url=https://github.com/netbootxyz/docker-netbootxyz/packages - org.opencontainers.image.documentation=https://netboot.xyz - org.opencontainers.image.source=https://github.com/netbootxyz/docker-netbootxyz - org.opencontainers.image.version=${{ env.VERSION_TAG }} - org.opencontainers.image.revision=${{ env.GITHUB_SHA }} - org.opencontainers.image.vendor=netboot.xyz - org.opencontainers.image.licenses=Apache-2.0 - org.opencontainers.image.ref.name=${{ env.GITHUB_SHA }} - org.opencontainers.image.title=netbootxyz - org.opencontainers.image.description=netboot.xyz official docker container - Your favorite operating systems in one place. A network-based bootable operating system installer based on iPXE. - - - name: Build and push image - if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success' - uses: docker/build-push-action@v3 - with: - push: false - context: . - file: ./Dockerfile - platforms: linux/amd64,linux/arm64 - build-args: | - WEBAPP_VERSION=${{ env.WEBAPP_RELEASE }} - VERSION=${{ env.VERSION_TAG }} - BUILD_DATE=${{ env.GITHUB_DATE }} - tags: | - ghcr.io/netbootxyz/netbootxyz:latest - ghcr.io/netbootxyz/netbootxyz:${{ github.sha }} - ghcr.io/netbootxyz/netbootxyz:${{ env.VERSION_TAG }} - labels: ${{ steps.meta.outputs.labels }} + - name: Build the Docker image + run: docker build .