Skip to content

Merge pull request #173 from wunderio/feature/SLT-987_helm-update #188

Merge pull request #173 from wunderio/feature/SLT-987_helm-update

Merge pull request #173 from wunderio/feature/SLT-987_helm-update #188

Workflow file for this run

name: Build and push docker images
on:
push:
branches:
- master
paths:
- '**/**/TAGS'
jobs:
changed_files:
name: Get changed tag files
runs-on: ubuntu-latest
env:
BUILD_CURRENT: ${{ github.sha }}
BUILD_PREVIOUS: ${{ github.event.before }}
outputs:
matrix: ${{ steps.changes.outputs.matrix}}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get changed TAGS files
id: changes
run: |
tagfile_list_json=$(git diff-tree --no-commit-id --name-only -r \
$BUILD_CURRENT $BUILD_PREVIOUS \
| grep TAGS$ \
| jq -Rsc '. / "\n" - [""]' )
echo "matrix=${tagfile_list_json}" > $GITHUB_OUTPUT
build_and_push_docker_hub:
name: Build and push to Docker Hub
runs-on: ubuntu-latest
# Secrets
# DOCKER_HUB_REGISTRY_URL: "wunderio"
env:
DOCKER_REGISTRY_URL: ${{ secrets.DOCKER_REGISTRY_URL }}
DOCKER_USER: ${{secrets.DOCKER_USER}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
needs: changed_files
strategy:
fail-fast: false
matrix:
dockerfile: ${{ fromJson(needs.changed_files.outputs.matrix) }}
if: ${{needs.changed_files.outputs.matrix}}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: docker login
run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- name: Build and push images
run: |
set -ex
tagsFilePath=${{matrix.dockerfile}}
# Remove "/TAGS" from the path
folder=${tagsFilePath%"/TAGS"};
# Split first two directores and use as image name and tag respectively.
# This only works with bash, make sure the shell is correct!
read IMAGE_NAME LEFTOVERS <<<$(IFS="/"; echo $folder);
# Read TAGS file, tag image with each tag and push to remote
IMAGE_ID=$DOCKER_REGISTRY_URL/$IMAGE_NAME
cat $tagsFilePath | while read TAG || [[ -n $TAG ]];
do
# Add tags
docker build $folder --file $folder/Dockerfile --tag $IMAGE_ID:$TAG
# Push image
docker push $IMAGE_ID:$TAG
done;
circleci-k8s-test-build:
name: Test released images
runs-on: ubuntu-latest
needs:
- build_and_push_docker_hub
strategy:
matrix:
project: [
{repo: "drupal-project-k8s", jobs: "4"},
{repo: "frontend-project-k8s", jobs: "4"},
{repo: "simple-project-k8s", jobs: "3"}
]
steps:
- uses: actions/checkout@v3
- name: Validate released images with ${{ matrix.project.repo }}
run: |
REPO_NAME="${{ matrix.project.repo }}"
JOB_COUNT="${{ matrix.project.jobs }}"
CIRCLECI_DEV_API_TOKEN="${{ secrets.CIRCLECI_DEV_API_TOKEN }}"
if [ -z "${REPO_NAME}" ] || [ -z "${CIRCLECI_DEV_API_TOKEN}" ] || [ -z "${JOB_COUNT}" ]; then
echo "Missing CIRCLECI_DEV_API_TOKEN secret"
exit 1
fi
echo "Running ${REPO_NAME} build on CircleCI"
echo "Project link: https://circleci.com/gh/wunderio/workflows/${REPO_NAME}"
base_api_url="https://circleci.com/api/v1.1/project/github/wunderio/${REPO_NAME}"
# Trigger a new deployment.
curl -s -X POST $base_api_url/build?circle-token=${CIRCLECI_DEV_API_TOKEN}
sleep 10
# Wait for deployment to be complete
while curl -s "$base_api_url?circle-token=${CIRCLECI_DEV_API_TOKEN}&limit=${JOB_COUNT}" | jq -e 'any(.[]; (.status == "running") or (.status == "queued"))' > /dev/null
do
echo "still running"
sleep 10
done
# Test that the build was successful
curl -s "$base_api_url?circle-token=${CIRCLECI_DEV_API_TOKEN}&limit=${JOB_COUNT}" | jq '.[] | { job_name: .workflows.job_name, status: .status }'
curl -s "$base_api_url?circle-token=${CIRCLECI_DEV_API_TOKEN}&limit=${JOB_COUNT}" | jq -e 'all(.[]; .status == "success")' > /dev/null