mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
128 lines
5.0 KiB
YAML
128 lines
5.0 KiB
YAML
name: docker-image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- '*.*.*'
|
|
pull_request:
|
|
|
|
jobs:
|
|
build-docker-image:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
-
|
|
name: Checkout
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
-
|
|
name: Prepare
|
|
id: prep
|
|
run: |
|
|
DOCKER_IMAGE=${DOCKERHUB_ORGANIZATION:-vagrantlibvirt}/vagrant-libvirt
|
|
VERSION=noop
|
|
if [ "${{ github.event_name }}" = "schedule" ]; then
|
|
VERSION=nightly
|
|
elif [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
VERSION=${GITHUB_REF#refs/tags/}
|
|
elif [[ $GITHUB_REF == refs/heads/* ]]; then
|
|
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
|
|
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
|
|
VERSION=edge
|
|
fi
|
|
elif [[ $GITHUB_REF == refs/pull/* ]]; then
|
|
VERSION=pr-${{ github.event.number }}
|
|
fi
|
|
TAGS="${DOCKER_IMAGE}:${VERSION}"
|
|
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
|
MINOR=${VERSION%.*}
|
|
MAJOR=v${MINOR%.*}
|
|
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
|
|
elif [ "${{ github.event_name }}" = "push" ]; then
|
|
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
|
|
fi
|
|
echo ::set-output name=version::${VERSION}
|
|
echo ::set-output name=tags::${TAGS}
|
|
echo ::set-output name=slim_tags::$(echo $TAGS | sed "s/,/-slim,/g")-slim
|
|
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
|
env:
|
|
DOCKERHUB_ORGANIZATION: ${{ secrets.DOCKERHUB_ORGANIZATION }}
|
|
-
|
|
name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v2
|
|
-
|
|
name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
with:
|
|
driver-opts: image=moby/buildkit:master
|
|
-
|
|
name: Cache Docker layers
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: /tmp/.buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildx-
|
|
-
|
|
name: Check have credentials
|
|
id: have_credentials
|
|
run: |
|
|
echo ::set-output name=access::${{ secrets.DOCKERHUB_USERNAME != '' && github.event_name != 'pull_request' }}
|
|
-
|
|
name: Login to DockerHub
|
|
if: steps.have_credentials.outputs.access == 'true'
|
|
uses: docker/login-action@v2
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
-
|
|
name: Build and push main image
|
|
id: docker_build
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64
|
|
push: ${{ steps.have_credentials.outputs.access }}
|
|
tags: ${{ steps.prep.outputs.tags }}
|
|
target: final
|
|
labels: |
|
|
org.opencontainers.image.title=${{ github.event.repository.name }}
|
|
org.opencontainers.image.description=${{ github.event.repository.description }}
|
|
org.opencontainers.image.url=${{ github.event.repository.html_url }}
|
|
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
|
|
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
|
|
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
|
|
cache-from: type=local,src=/tmp/.buildx-cache
|
|
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
|
|
-
|
|
name: Build and push slim image
|
|
id: docker_build_slim
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64
|
|
push: ${{ steps.have_credentials.outputs.access }}
|
|
tags: ${{ steps.prep.outputs.slim_tags }}
|
|
target: slim
|
|
labels: |
|
|
org.opencontainers.image.title=${{ github.event.repository.name }}
|
|
org.opencontainers.image.description=${{ github.event.repository.description }}
|
|
org.opencontainers.image.url=${{ github.event.repository.html_url }}
|
|
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
|
|
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
|
|
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
|
|
cache-from: type=local,src=/tmp/.buildx-cache
|
|
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
|
|
-
|
|
name: Image digest
|
|
run: echo ${{ steps.docker_build.outputs.digest }}
|
|
-
|
|
name: Image digest Slim
|
|
run: echo ${{ steps.docker_build_slim.outputs.digest }}
|