forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed '.github/docker-actions/' changes from f967b159ee..60437cbde7
60437cbde7 Merge pull request #2 from WAGO/feat/oelh/fix-version 69c1d2a556 Change component actions to release version v1.0 934e84a197 Merge pull request #1 from WAGO/feat/oelh/extracted a04bdaa494 Extract common docker actions git-subtree-dir: .github/docker-actions git-subtree-split: 60437cbde75455f2248a81de61dc32264aacca26
- Loading branch information
Showing
4 changed files
with
384 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
name: Docker make | ||
description: Call docker make targets | ||
author: nosamad | ||
|
||
inputs: | ||
targets: | ||
description: Make targets string | ||
required: true | ||
golang-version: | ||
description: Go language version string | ||
required: true | ||
base-debian-distro: | ||
description: Base debian distro string | ||
required: true | ||
host-arch: | ||
description: Host arch string | ||
required: false | ||
default: '' | ||
target-platform: | ||
description: Target platform string | ||
required: false | ||
default: '' | ||
check-config-commit: | ||
description: Check config script commit identifier | ||
required: false | ||
default: 2b0755b936416834e14208c6c37b36977e67ea35 | ||
buildx-build-args: | ||
description: Additional buildx build arguments string | ||
required: false | ||
default: '' | ||
buildx-driver-opts: | ||
description: Buildx driver options string | ||
required: false | ||
default: '' | ||
build-output: | ||
description: Build output path | ||
required: false | ||
default: bundles | ||
make-args: | ||
description: Additional make arguments string | ||
required: false | ||
default: '' | ||
project-version: | ||
description: Project version string | ||
required: false | ||
default: '' | ||
|
||
outputs: | ||
buildx-cache: | ||
description: Path to Buildx cache string | ||
value: ${{ steps.setup-docker-make.outputs.buildx-cache }} | ||
buildx-cache-key: | ||
description: Key of Buildx cache string | ||
value: ${{ steps.setup-docker-make.outputs.buildx-cache-key }} | ||
target-platform-id: | ||
description: Target platform id string | ||
value: ${{ steps.setup-docker-make.outputs.target-platform-id }} | ||
target-id: | ||
description: Target id string | ||
value: ${{ steps.setup-docker-make.outputs.target-id }} | ||
golang-imageref: | ||
description: Go image reference string | ||
value: ${{ steps.setup-docker-make.outputs.golang-imageref }} | ||
|
||
runs: | ||
using: composite | ||
|
||
steps: | ||
- name: Check environment | ||
run: | | ||
command -V make | ||
command -V bash | ||
command -V rm | ||
command -V mv | ||
shell: sh | ||
|
||
- name: Set up node for docker make | ||
id: setup-docker-make | ||
uses: WAGO/docker-actions/setup-docker-make@release/v1.0 | ||
with: | ||
targets: ${{ inputs.targets }} | ||
golang-version: ${{ inputs.golang-version }} | ||
base-debian-distro: ${{ inputs.base-debian-distro }} | ||
host-arch: ${{ inputs.host-arch }} | ||
target-platform: ${{ inputs.target-platform }} | ||
check-config-commit: ${{ inputs.check-config-commit }} | ||
buildx-driver-opts: ${{ inputs.buildx-driver-opts }} | ||
project-version: ${{ inputs.project-version }} | ||
|
||
- name: Make targets | ||
env: | ||
GOLANG_IMAGE: ${{ steps.setup-docker-make.outputs.golang-imageref }} | ||
BASE_DEBIAN_DISTRO: ${{ inputs.base-debian-distro }} | ||
BUILDX_CACHE: ${{ steps.setup-docker-make.outputs.buildx-cache }} | ||
BIND_DIR: ${{ inputs.build-output }} | ||
run: | | ||
readarray -t make_targets < <(cat << EOF | ||
${{ inputs.targets }}EOF | ||
) | ||
readarray -t buildx_build_args < <(cat << EOF | ||
${{ inputs.buildx-build-args }}EOF | ||
) | ||
readarray -t make_args < <(cat << EOF | ||
${{ inputs.make-args }}EOF | ||
) | ||
docker_build_args=() | ||
docker_build_args+=("--cache-from type=local,src=${BUILDX_CACHE}") | ||
docker_build_args+=("--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max") | ||
docker_build_args+=("--build-arg BASE_DEBIAN_DISTRO") | ||
docker_build_args+=("--build-arg GOLANG_IMAGE") | ||
docker_build_args+=("${buildx_build_args[*]}") | ||
make "${make_targets[@]}" "${make_args[@]}" DOCKER_BUILD_ARGS="${docker_build_args[*]}" DOCKER_CROSSPLATFORMS="${{ inputs.target-platform }}" | ||
shell: bash | ||
|
||
# Temp fix | ||
# https://github.com/docker/build-push-action/issues/252 | ||
# https://github.com/moby/buildkit/issues/1896 | ||
- name: Move cache | ||
env: | ||
BUILDX_CACHE: ${{ steps.setup-docker-make.outputs.buildx-cache }} | ||
run: | | ||
rm -rf "${BUILDX_CACHE}" | ||
mv /tmp/.buildx-cache-new "${BUILDX_CACHE}" | ||
shell: sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Retrieves project information | ||
description: Retrieves project information | ||
author: nosamad | ||
|
||
inputs: | ||
version: | ||
description: Version string | ||
default: '' | ||
required: false | ||
|
||
outputs: | ||
version: | ||
description: Effective project version string | ||
value: ${{ steps.setup-project-info.outputs.version }} | ||
buildtime: | ||
description: Build time string | ||
value: ${{ steps.setup-project-info.outputs.buildtime }} | ||
|
||
runs: | ||
using: composite | ||
|
||
steps: | ||
- name: Check environment | ||
run: | | ||
command -V date | ||
command -V git | ||
command -V sed | ||
command -V bash | ||
shell: sh | ||
|
||
- name: Set up Project information | ||
id: setup-project-info | ||
env: | ||
VERSION: ${{ inputs.version }} | ||
run: | | ||
export TZ=UTC | ||
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(git log -1 --pretty='%ct')}" | ||
echo "SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH}" >> "${GITHUB_ENV}" | ||
static_version="$VERSION" | ||
if [[ -z "${static_version}" ]] || [[ "${static_version}" == *-dev ]]; then | ||
git_date="$(date --utc --date "@${SOURCE_DATE_EPOCH}" +'%Y%m%d%H%M%S')" | ||
git_commit="$(git log -1 --pretty='%h')" | ||
static_version="0.0.0-${git_date}-${git_commit}" | ||
fi | ||
echo "::set-output name=version::${static_version}" | ||
buildtime="$(date -u -d "@${SOURCE_DATE_EPOCH}" --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')" | ||
echo "::set-output name=buildtime::${buildtime}" | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
name: Set up Docker Make | ||
description: Set up for Docker make | ||
author: nosamad | ||
|
||
inputs: | ||
targets: | ||
description: Make targets string | ||
required: false | ||
default: '' | ||
golang-version: | ||
description: Go language version string | ||
required: false | ||
default: latest | ||
base-debian-distro: | ||
description: Base debian distro string | ||
required: false | ||
default: '' | ||
host-arch: | ||
description: Host arch string | ||
required: false | ||
default: '' | ||
target-platform: | ||
description: 'Target platform string' | ||
required: false | ||
default: '' | ||
check-config-commit: | ||
description: Check config script commit identifier string | ||
required: true | ||
buildx-driver-opts: | ||
description: Buildx driver options string | ||
required: false | ||
default: '' | ||
project-version: | ||
description: Project version string | ||
required: false | ||
default: '' | ||
|
||
outputs: | ||
buildx-cache: | ||
description: Path to Buildx cache string | ||
value: ${{ steps.set-metainfo.outputs.buildx-cache }} | ||
buildx-cache-key: | ||
description: Key of Buildx cache string | ||
value: ${{ steps.set-metainfo.outputs.buildx-cache-key }} | ||
target-platform-id: | ||
description: Target platform id string | ||
value: ${{ steps.set-metainfo.outputs.target-platform-id }} | ||
target-id: | ||
description: Target id string | ||
value: ${{ steps.set-metainfo.outputs.target-id }} | ||
targets: | ||
description: Target names as string | ||
value: ${{ steps.set-metainfo.outputs.targets }} | ||
golang-imageref: | ||
description: Go image reference string | ||
value: ${{ steps.subst-golang_imageref.outputs.result }} | ||
|
||
runs: | ||
using: composite | ||
|
||
steps: | ||
- name: Check environment | ||
run: | | ||
command -V tr | ||
command -V sed | ||
command -V curl | ||
command -V bash | ||
command -V jq | ||
shell: sh | ||
|
||
- name: Retrieve Project information | ||
id: setup-project-info | ||
uses: WAGO/docker-actions/project-info@release/v1.0 | ||
with: | ||
version: ${{ inputs.project-version }} | ||
|
||
- name: Set Meta information | ||
id: set-metainfo | ||
run: | | ||
target_platform_id='${{ inputs.target-platform }}' | ||
if [[ -z "${target_platform_id}" ]]; then | ||
target_platform_id='${{ runner.os }}' | ||
fi | ||
target_platform_id="$(echo "${target_platform_id}" | tr '[:upper:]' '[:lower:]')" | ||
target_platform_id="$(echo "${target_platform_id}" | tr \/ _)" | ||
echo "target-platform-id=${target_platform_id}" | ||
echo "::set-output name=target-platform-id::${target_platform_id}" | ||
readarray -t make_targets < <(cat << EOF | ||
${{ inputs.targets }}EOF | ||
) | ||
make_targets_str="${make_targets[*]}" | ||
target_id="$(echo "${make_targets_str}" | tr \/ _)" | ||
echo "target-id=${target_id}" | ||
echo "::set-output name=target-id::${target_id}" | ||
echo "targets=${targets}" | ||
echo "::set-output name=targets::${make_targets_str}" | ||
echo "::set-output name=buildx-cache::/tmp/.buildx-cache" | ||
buildx_cache_key="${target_platform_id}-buildx-" | ||
restore_keys=("${buildx_cache_key}") | ||
if [[ -n "${target_id}" ]]; then | ||
buildx_cache_key="${buildx_cache_key}${target_id}-" | ||
restore_keys=("${buildx_cache_key}" "${restore_keys[@]}") | ||
fi | ||
buildx_cache_key="${buildx_cache_key}${GITHUB_SHA}" | ||
echo "::set-output name=buildx-cache-key::${buildx_cache_key}" | ||
restore_keys_uriencoded="$(printf '%s\n' "${restore_keys[@]}" | jq -sRr @uri)" | ||
echo "::set-output name=buildx-cache-restore-keys::${restore_keys_uriencoded}" | ||
echo 'VERSION=${{ steps.setup-project-info.outputs.version }}' >> "${GITHUB_ENV}" | ||
echo 'BUILDTIME=${{ steps.setup-project-info.outputs.buildtime }}' >> "${GITHUB_ENV}" | ||
shell: bash | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
with: | ||
image: tonistiigi/binfmt:latest | ||
platforms: all | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
with: | ||
version: latest | ||
driver-opts: | | ||
${{ inputs.buildx-driver-opts }} | ||
install: true | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.set-metainfo.outputs.buildx-cache }} | ||
key: ${{ steps.set-metainfo.outputs.buildx-cache-key }} | ||
restore-keys: ${{ steps.set-metainfo.outputs.buildx-cache-restore-keys }} | ||
|
||
- name: Check Docker configuration | ||
env: | ||
CHECK_CONFIG_COMMIT: ${{ inputs.check-config-commit }} | ||
run: | | ||
curl -fsSL -o './check-config.sh' "https://raw.githubusercontent.com/moby/moby/${CHECK_CONFIG_COMMIT}/contrib/check-config.sh" \ | ||
&& bash './check-config.sh' \ | ||
|| true | ||
shell: bash | ||
|
||
- name: Get go language image reference | ||
id: subst-golang_imageref | ||
uses: WAGO/docker-actions/subst-imageref@release/v1.0 | ||
with: | ||
name: golang | ||
version: ${{ inputs.golang-version }} | ||
release: ${{ inputs.base-debian-distro }} | ||
arch: ${{ inputs.host-arch }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: "Subst image reference" | ||
description: "Stubst architecture specific docker image reference" | ||
author: "nosamad" | ||
|
||
inputs: | ||
name: | ||
description: 'Image name string' | ||
required: true | ||
version: | ||
description: 'Image version string' | ||
default: latest | ||
required: false | ||
release: | ||
description: 'Image release string' | ||
default: '' | ||
required: false | ||
arch: | ||
description: 'Image arch string' | ||
default: '' | ||
required: false | ||
repo-templ: | ||
description: 'Image repository template string' | ||
default: '%ARCH_PREFIX%%NAME%:%VERSION%%RELEASE_SUFFIX%' | ||
required: false | ||
|
||
outputs: | ||
result: | ||
description: "Substituted docker image reference string" | ||
value: ${{ steps.subst-image.outputs.result }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Check environment | ||
run: | | ||
command -V sed | ||
shell: sh | ||
|
||
- name: Subst image reference | ||
id: subst-image | ||
run: | | ||
if [ ! -z '${{ inputs.arch }}' ]; then | ||
arch_prefix='${{ inputs.arch }}/' | ||
fi | ||
if [ ! -z '${{ inputs.release }}' ]; then | ||
release_suffix='-${{ inputs.release }}' | ||
fi | ||
image="$(echo "${{ inputs.repo-templ }}" \ | ||
| sed -e "s#%ARCH_PREFIX%#${arch_prefix}#" \ | ||
-e 's#%NAME%#${{ inputs.name }}#' \ | ||
-e 's#%VERSION%#${{ inputs.version }}#' \ | ||
-e "s#%RELEASE_SUFFIX%#${release_suffix}#" \ | ||
)" | ||
echo "result=$image" | ||
echo "::set-output name=result::$image" | ||
shell: sh |