2023-06-04 10:11:24 +02:00
|
|
|
name: Build and upload Docker images
|
|
|
|
|
2023-05-27 16:15:39 +02:00
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
- master
|
|
|
|
schedule:
|
|
|
|
- cron: '37 7 * * 3'
|
|
|
|
workflow_dispatch:
|
|
|
|
inputs:
|
|
|
|
images:
|
|
|
|
description: 'List of images to be built'
|
|
|
|
required: false
|
|
|
|
type: string
|
|
|
|
|
2023-06-13 10:24:57 +02:00
|
|
|
# Pause on concurrent builds
|
|
|
|
concurrency:
|
|
|
|
group: build-docker-images
|
|
|
|
|
2023-05-27 16:15:39 +02:00
|
|
|
jobs:
|
|
|
|
docker-images:
|
|
|
|
runs-on: ubuntu-latest
|
2023-05-29 19:53:39 +08:00
|
|
|
permissions:
|
|
|
|
packages: write
|
2023-05-27 16:15:39 +02:00
|
|
|
steps:
|
|
|
|
- name: Check out repository code
|
|
|
|
# https://github.com/marketplace/actions/checkout
|
2023-09-20 13:28:17 +02:00
|
|
|
uses: actions/checkout@v4
|
2023-05-27 16:15:39 +02:00
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
2023-06-04 10:11:24 +02:00
|
|
|
|
2023-05-27 16:15:39 +02:00
|
|
|
- name: Set up QEMU
|
|
|
|
# https://github.com/marketplace/actions/docker-setup-qemu
|
2023-09-20 13:28:17 +02:00
|
|
|
uses: docker/setup-qemu-action@v3
|
2023-06-04 10:11:24 +02:00
|
|
|
|
2023-05-27 16:15:39 +02:00
|
|
|
- name: Set up Docker Buildx
|
|
|
|
# https://github.com/marketplace/actions/docker-setup-buildx
|
2023-09-20 13:28:17 +02:00
|
|
|
uses: docker/setup-buildx-action@v3
|
2023-06-04 10:11:24 +02:00
|
|
|
|
|
|
|
- name: Login to DockerHub Registry
|
2023-05-27 16:15:39 +02:00
|
|
|
# https://github.com/marketplace/actions/docker-login
|
2023-06-04 10:11:24 +02:00
|
|
|
# set the condition depending on whether you want to login to Docker.
|
|
|
|
if: true
|
2023-09-20 13:28:17 +02:00
|
|
|
uses: docker/login-action@v3
|
2023-05-27 16:15:39 +02:00
|
|
|
with:
|
2023-05-29 20:23:27 +08:00
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
2023-06-04 10:11:24 +02:00
|
|
|
|
|
|
|
- name: Login to GitHub Container Registry
|
|
|
|
# https://github.com/marketplace/actions/docker-login
|
|
|
|
# set the condition depending on whether you want to login to ghcr.io.
|
2023-06-19 13:00:23 +09:30
|
|
|
if: true
|
2023-09-20 13:28:17 +02:00
|
|
|
uses: docker/login-action@v3
|
2023-06-04 10:11:24 +02:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.repository_owner }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
2023-05-27 16:15:39 +02:00
|
|
|
- name: Install python requirements
|
|
|
|
run: python3 -m pip install --requirement .github/bin/requirements.txt
|
2023-06-04 10:11:24 +02:00
|
|
|
|
2023-05-27 16:15:39 +02:00
|
|
|
- name: Build and push images
|
|
|
|
env:
|
2023-06-12 15:21:45 +02:00
|
|
|
# DOCKER_REPOSITORY - Repository for name-only images
|
2023-10-26 21:37:01 +02:00
|
|
|
# Using multiple repositories will build images in all of them.
|
|
|
|
DOCKER_REPOSITORY: |
|
|
|
|
# DockerHub:
|
2023-06-19 13:00:23 +09:30
|
|
|
${{ secrets.DOCKERHUB_REPOSITORY }}
|
2023-10-26 21:37:01 +02:00
|
|
|
# GitHub Container Registry:
|
2023-06-19 13:00:23 +09:30
|
|
|
ghcr.io/${{ github.repository_owner }}
|
2023-06-04 10:11:24 +02:00
|
|
|
#
|
|
|
|
# Variables whose name are starting with "DOCKER_LOGIN"
|
|
|
|
# contain the user/password for a docker registry.
|
|
|
|
# They are only needed to authenticate into private repositories.
|
2023-05-28 17:49:57 +02:00
|
|
|
#
|
2023-05-27 16:15:39 +02:00
|
|
|
# DockerHub:
|
2023-06-04 10:11:24 +02:00
|
|
|
#DOCKER_LOGIN_DH: >-
|
|
|
|
# docker.io
|
|
|
|
# ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
# ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
#
|
|
|
|
# GitHub Container Registry:
|
|
|
|
#DOCKER_LOGIN_GH: >-
|
|
|
|
# ghcr.io
|
|
|
|
# ${{ github.repository_owner }}
|
|
|
|
# ${{ secrets.GITHUB_TOKEN }}
|
2023-05-27 16:15:39 +02:00
|
|
|
#
|
|
|
|
IMAGES: ${{ inputs.images }}
|
|
|
|
run: |
|
2023-10-26 21:37:01 +02:00
|
|
|
DOCKER_REPOSITORY=$(echo "$DOCKER_REPOSITORY" | sed '/^#/d')
|
2023-05-27 16:15:39 +02:00
|
|
|
set -f
|
|
|
|
set -- $IMAGES
|
|
|
|
set +f
|
2023-07-05 13:38:09 +02:00
|
|
|
|
|
|
|
# get image version
|
|
|
|
get_image_version() {
|
2023-07-09 00:34:45 +02:00
|
|
|
local object
|
|
|
|
object='config.Labels."org.opencontainers.image.version"'
|
2023-07-05 13:38:09 +02:00
|
|
|
docker buildx imagetools inspect --format '{{json .Image}}' "$1" | \
|
2023-07-09 00:34:45 +02:00
|
|
|
jq -r ".$object // .\"linux/amd64\".$object // empty"
|
2023-07-05 13:38:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# special treatment for kalilinux: rebuild when image version changes
|
|
|
|
if [ "$GITHUB_EVENT_NAME" = "schedule" ]; then
|
|
|
|
basever=$(get_image_version kalilinux/kali-last-release:amd64)
|
|
|
|
imagever=$(get_image_version gns3/kalilinux)
|
|
|
|
[ -z "$basever" ] || [ "$basever" = "$imagever" ] || \
|
|
|
|
set -- "$@" kalilinux
|
|
|
|
fi
|
|
|
|
|
2023-05-27 16:15:39 +02:00
|
|
|
# use option --dir to use a subdirectory as a docker base dir
|
2023-12-15 19:51:41 +01:00
|
|
|
python3 "$GITHUB_WORKSPACE/.github/bin/docker_make" --dir "docker" "$@"
|