Skip to content

test docker build

test docker build #136

Workflow file for this run

name: Build image to DockerHub
on:
push:
branches: [main]
paths:
- "apps/*/Dockerfile"
- "apps/*/cmd.sh"
- "apps/*/entrypoint.sh"
jobs:
test:
name: Build Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Get applist
id: getlist
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)
echo "APP_LISTS=$app_list" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker images
run: |
IFS=',' read -ra APP_LISTS <<< "$APP_LISTS"
for APP in "${APP_LISTS[@]}"; do
TAG=$(grep 'LABEL version' "apps/$APP/Dockerfile" | cut -d'"' -f2)
echo $TAG
TAGS=$(echo $TAG | awk -F. '{for(i=1;i<=NF;i++){printf (i==1?"":",")"%s",substr($0,1,index($0,$i"."$((i+1)))-1)}}' | sed 's/,$//')
echo $TAGS
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
uses: mr-smithers-excellent/docker-build-push@v5
with:
image: websoft9dev/${{env.APP}}
tags: ${{env.TAGS}}
registry: docker.io
dockerfile: ${{env.DOCKERFILE}}
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: websoft9dev/${{env.APP}}
readme-filepath: ${{env.README}}
done
if: env.APP_LISTS != ''