test docker build #147
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
name: Build image to DockerHub | |
on: | |
push: | |
branches: [main] | |
paths: | |
- "apps/*/Dockerfile" | |
- "apps/*/cmd.sh" | |
- "apps/*/entrypoint.sh" | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 | |
- id: set-matrix | |
run: | | |
git diff --name-only HEAD^ HEAD | |
changed_files=$(git diff --name-only HEAD^ HEAD) | |
app_list=$(echo "$changed_files" | grep -E 'apps/.*/(Dockerfile|cmd.sh|entrypoint.sh)' | awk -F'/' '{print $2}' | sort | uniq) | |
app_list_json=$(echo $app_list | jq -R -s -c 'split(" ")') | |
echo "::set-output name=matrix::{\"app\": $app_list_json}" | |
build: | |
needs: setup | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{fromJson(needs.setup.outputs.matrix)}} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 | |
- name: Build and push Docker images | |
run: | | |
APP=${{ matrix.app }} | |
TAG=$(grep 'LABEL version' "apps/$APP/Dockerfile" | cut -d'"' -f2 | xargs) | |
echo $APP version is $TAG | |
if [[ "$TAG" == *"-"* ]]; then | |
TAGS="$TAG" | |
else | |
IFS='.' read -ra PARTS <<< "$TAG" | |
TAGS="latest" | |
TAG_PART="" | |
for i in "${!PARTS[@]}"; do | |
if [ "$i" -eq 0 ]; then | |
TAG_PART="${PARTS[$i]}" | |
else | |
TAG_PART="${TAG_PART}.${PARTS[$i]}" | |
fi | |
TAGS="${TAGS},${TAG_PART}" | |
done | |
fi | |
echo "Building and pushing Docker image for $APP with tags: $TAGS" | |
echo "TAGS=$TAGS" >> $GITHUB_ENV | |
echo "APP=$APP" >> $GITHUB_ENV | |
echo "DOCKERFILE=apps/$APP/Dockerfile" >> $GITHUB_ENV | |
echo "README=apps/$APP/README.md" >> $GITHUB_ENV | |
- name: Build & push Docker image | |
uses: mr-smithers-excellent/docker-build-push@v5 | |
with: | |
image: websoft9dev/${{env.APP}} | |
tags: ${{env.TAGS}} | |
registry: docker.io | |
dockerfile: ${{env.DOCKERFILE}} | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Docker Hub Description | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
repository: websoft9dev/${{env.APP}} | |
readme-filepath: ${{env.README}} | |
if: needs.setup.outputs.matrix != '' | |