-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from docksal/develop
Release 1.10.0
- Loading branch information
Showing
10 changed files
with
308 additions
and
102 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,63 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Generates docker images tags for the docker/build-push-action@v2 action depending on the branch/tag. | ||
# Image tag format: | ||
# develop => image:[version-]edge[-flavor] | ||
# master => image:[version][-][flavor] | ||
# semver tag => image:[version-]major.minor[-flavor] | ||
|
||
declare -a registryArr | ||
registryArr+=("docker.io") # Docker Hub | ||
registryArr+=("ghcr.io") # GitHub Container Registry | ||
|
||
declare -a imageTagArr | ||
|
||
# Join arguments with hyphen (-) as a delimiter | ||
# Usage: join <arg1> [<argn>] | ||
join() { | ||
local IFS='-' # join delimiter | ||
echo "$*" | ||
} | ||
|
||
# feature/* => sha-xxxxxxx | ||
# Note: disabled | ||
#if [[ "${GITHUB_REF}" =~ "refs/heads/feature/" ]]; then | ||
# GIT_SHA7=$(echo ${GITHUB_SHA} | cut -c1-7) # Short SHA (7 characters) | ||
# imageTagArr+=("${IMAGE}:${VERSION}-sha-${GIT_SHA7}") | ||
#fi | ||
|
||
# develop => version-edge | ||
if [[ "${GITHUB_REF}" == "refs/heads/develop" ]]; then | ||
tag=$(join ${VERSION} edge ${FLAVOR}) | ||
imageTagArr+=("${IMAGE}:${tag}") | ||
fi | ||
|
||
# master => version | ||
if [[ "${GITHUB_REF}" == "refs/heads/master" ]]; then | ||
tag=$(join ${VERSION} ${FLAVOR}) | ||
imageTagArr+=("${IMAGE}:${tag}") | ||
fi | ||
|
||
# tags/v1.0.0 => 1.0 | ||
if [[ "${GITHUB_REF}" =~ "refs/tags/" ]]; then | ||
# Extract version parts from release tag | ||
IFS='.' read -a release_arr <<< "${GITHUB_REF#refs/tags/}" | ||
releaseMajor=${release_arr[0]#v*} # 2.7.0 => "2" | ||
releaseMinor=${release_arr[1]} # "2.7.0" => "7" | ||
imageTagArr+=("${IMAGE}:$(join ${VERSION} ${FLAVOR})") | ||
imageTagArr+=("${IMAGE}:$(join ${VERSION} ${releaseMajor} ${FLAVOR})") | ||
imageTagArr+=("${IMAGE}:$(join ${VERSION} ${releaseMajor}.${releaseMinor} ${FLAVOR})") | ||
fi | ||
|
||
# Build an array of registry/image:tag values | ||
declare -a repoImageTagArr | ||
for registry in ${registryArr[@]}; do | ||
for imageTag in ${imageTagArr[@]}; do | ||
repoImageTagArr+=("${registry}/${imageTag}") | ||
done | ||
done | ||
|
||
# Print with new lines for output in build logs | ||
(IFS=$'\n'; echo "${repoImageTagArr[*]}") | ||
# Using newlines in outputs variables does not seem to work, so we'll use comas | ||
(IFS=$','; echo "::set-output name=tags::${repoImageTagArr[*]}") |
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,170 @@ | ||
name: Docker Build and Push | ||
|
||
on: | ||
schedule: | ||
- cron: '0 10 * * 0' # everyday sunday at 10am | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
- feature/* | ||
tags: | ||
- 'v*.*.*' | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
build-test-push: | ||
name: Build, Test, Push | ||
runs-on: ubuntu-20.04 | ||
|
||
env: | ||
IMAGE: docksal/ci-agent | ||
|
||
steps: | ||
- | ||
name: Install prerequisites for tests | ||
run: | | ||
set -xeuo pipefail | ||
# Install bats for tests | ||
git clone https://github.com/bats-core/bats-core.git | ||
cd bats-core | ||
sudo ./install.sh /usr/local | ||
bats -v | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v2 | ||
#- | ||
# name: Set up QEMU | ||
# uses: docker/setup-qemu-action@v1 | ||
# buildx has some glitches with local upstream (FROM) images. Disabled. | ||
#- | ||
# name: Set up Docker Buildx | ||
# uses: docker/setup-buildx-action@v1 | ||
- | ||
name: Check Docker | ||
run: | | ||
docker version | ||
docker info | ||
- | ||
name: Login to Docker Hub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- | ||
name: Login to GitHub Container Registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ secrets.GHCR_USERNAME }} | ||
password: ${{ secrets.GHCR_TOKEN }} | ||
- | ||
# Calculates docker image tags for the given build context | ||
# The output is used in build and push step as `tags: ${{ steps.docker_meta.outputs.tags }}` | ||
# See https://github.com/crazy-max/ghaction-docker-meta | ||
name: Docker meta | ||
id: docker_meta | ||
uses: crazy-max/ghaction-docker-meta@v1 | ||
with: | ||
# List of Docker images to use as base name for tags | ||
images: | | ||
${{ env.IMAGE }} | ||
ghcr.io/${{ env.IMAGE }} | ||
tag-sha: true # add git short SHA as Docker tag | ||
- | ||
# Build for local use | ||
name: Build image (base) | ||
run: make build FLAVOR=base | ||
- | ||
# Build for local use | ||
name: Build image (php) | ||
run: make build FLAVOR=php | ||
- | ||
# Print image info | ||
name: Docker image info | ||
run: | | ||
set -xeuo pipefail | ||
docker image ls | grep "${{ env.IMAGE }}" | ||
docker image inspect "${{ env.IMAGE }}:base-build" | ||
docker image inspect "${{ env.IMAGE }}:php-build" | ||
# Cache image layers in the registry | ||
- | ||
name: Push image cache (base) | ||
uses: docker/build-push-action@v2 | ||
env: | ||
IMAGE_CACHE: ghcr.io/${{ env.IMAGE }}:base-build | ||
with: | ||
context: base | ||
file: base/Dockerfile | ||
#platforms: linux/amd64,linux/arm64 | ||
tags: ${{ env.IMAGE_CACHE }} # Build cache tag in ghcr.io | ||
push: ${{ github.event_name != 'pull_request' }} # Don't push for PRs | ||
cache-to: type=inline # Write the cache metadata into the image configuration | ||
- | ||
name: Push image cache (php) | ||
uses: docker/build-push-action@v2 | ||
env: | ||
IMAGE_CACHE: ghcr.io/${{ env.IMAGE }}:php-build | ||
with: | ||
context: php | ||
file: php/Dockerfile | ||
#platforms: linux/amd64,linux/arm64 | ||
tags: ${{ env.IMAGE_CACHE }} # Build cache tag in ghcr.io | ||
push: ${{ github.event_name != 'pull_request' }} # Don't push for PRs | ||
cache-to: type=inline # Write the cache metadata into the image configuration | ||
|
||
# Tests | ||
- | ||
name: Test image (base) | ||
run: make test FLAVOR=base | ||
- | ||
name: Test image (php) | ||
run: make test FLAVOR=php | ||
|
||
- | ||
# Generate image meta information | ||
name: Docker image tags (base) | ||
id: docker_tags_base | ||
run: make tags FLAVOR=base | ||
- | ||
# Generate image meta information | ||
name: Docker image tags (php) | ||
id: docker_tags_php | ||
run: make tags FLAVOR=php | ||
- | ||
# Push final image to the registry | ||
# This will pick-up the build cache from the local build step | ||
name: Push image (base) | ||
# Don't run if the list of tags is empty | ||
# Note: using tags from docker_tags (custom) | ||
if: ${{ steps.docker_tags_base.outputs.tags != '' }} | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: base | ||
file: base/Dockerfile | ||
#platforms: linux/amd64,linux/arm64 | ||
tags: ${{ steps.docker_tags_base.outputs.tags }} # Note: using tags from docker_tags (custom script) | ||
labels: ${{ steps.docker_meta.outputs.labels }} # Note: using lables from docker_meta | ||
push: ${{ github.event_name != 'pull_request' }} # Don't push for PRs | ||
cache-to: type=inline # Write the cache metadata into the image configuration | ||
|
||
- | ||
# Push final image to the registry | ||
# This will pick-up the build cache from the local build step | ||
name: Push image (php) | ||
# Don't run if the list of tags is empty | ||
# Note: using tags from docker_tags (custom) | ||
if: ${{ steps.docker_tags_php.outputs.tags != '' }} | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: php | ||
file: php/Dockerfile | ||
#platforms: linux/amd64,linux/arm64 | ||
tags: ${{ steps.docker_tags_php.outputs.tags }} # Note: using tags from docker_tags (custom script) | ||
labels: ${{ steps.docker_meta.outputs.labels }} # Note: using lables from docker_meta | ||
push: ${{ github.event_name != 'pull_request' }} # Don't push for PRs | ||
cache-to: type=inline # Write the cache metadata into the image configuration |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.