-
Notifications
You must be signed in to change notification settings - Fork 27
53 lines (46 loc) · 1.62 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
done
if: env.APP_LISTS != ''