58 lines
2.5 KiB
YAML
58 lines
2.5 KiB
YAML
name: Image Build
|
|
|
|
on: [push]
|
|
|
|
jobs:
|
|
init:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
iventoy: ${{ steps.iventoy.outputs.version }}
|
|
buildOrNot: ${{ steps.buildOrNot.outputs.buildOrNot }}
|
|
steps:
|
|
- name: Install jq
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install jq -y
|
|
|
|
- name: get latest versions
|
|
id: iventoy
|
|
run: |
|
|
version=$(curl -s https://api.github.com/repos/ventoy/PXE/releases/latest | grep "tag_name" | cut -d'"' -f4)
|
|
echo "version=${version#'v'}" >> iventoy_output.txt
|
|
echo "::set-output name=version::${version#'v'}"
|
|
|
|
- name: Check labels of the latest image on Docker Hub
|
|
id: buildOrNot
|
|
run: |
|
|
repo=${1:-$GITEA_REPO}
|
|
tag=${2:-latest}
|
|
token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" | jq -r '.token')
|
|
manifest=$(curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -H "Authorization: Bearer $token" -s "https://registry-1.docker.io/v2/${repo}/manifests/${tag}")
|
|
echo "Manifest response:"
|
|
echo "$manifest"
|
|
digest=$(echo "$manifest" | jq -r .config.digest)
|
|
latest=$(curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -H "Authorization: Bearer $token" -s -L "https://registry-1.docker.io/v2/${repo}/blobs/${digest}" | jq . | grep -Ew "IVENTOY" | cut -d'"' -f4)
|
|
echo "Latest label: $latest"
|
|
echo "buildOrNot=$([ "$latest" != "$GITEA_IVENTOY" ] && echo "true" || echo "$GITEA_FORCE_BUILD")" >> iventoy_output.txt
|
|
echo "::set-output name=buildOrNot::$([ "$latest" != "$GITEA_IVENTOY" ] && echo "true" || echo "$GITEA_FORCE_BUILD")"
|
|
|
|
docker:
|
|
name: iventoy image
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- init
|
|
if: ${{ needs.init.outputs.buildOrNot == 'true' }}
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
echo "Checkout repository"
|
|
- name: Login to Docker Hub
|
|
run: |
|
|
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN
|
|
- name: Build and push
|
|
run: |
|
|
docker build -t $DOCKERHUB_USERNAME/${GITEA_REPOSITORY_NAME}:${GITEA_IVENTOY} --build-arg IVENTOY=$GITEA_IVENTOY .
|
|
docker push $DOCKERHUB_USERNAME/${GITEA_REPOSITORY_NAME}:${GITEA_IVENTOY}
|
|
docker tag $DOCKERHUB_USERNAME/${GITEA_REPOSITORY_NAME}:${GITEA_IVENTOY} $DOCKERHUB_USERNAME/${GITEA_REPOSITORY_NAME}:latest
|
|
docker push $DOCKERHUB_USERNAME/${GITEA_REPOSITORY_NAME}:latest
|