-
Notifications
You must be signed in to change notification settings - Fork 1
44 lines (35 loc) · 1.26 KB
/
dockerhub-build.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
name: Build and Push Docker Images
on:
push:
branches:
- main
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Login to Docker Hub
run: echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- name: Determine changed Dockerfiles
id: find-dockerfiles
run: |
changed_files=$(git diff --name-only HEAD~1 || git ls-files --exclude='*')
dockerfiles=$(find . -name "Dockerfile" -printf '%P\n')
changed_dockerfiles=""
for file in $dockerfiles; do
if [[ $changed_files == *"$file"* ]]; then
changed_dockerfiles+=" $file"
fi
done
echo "::set-output name=changed_dockerfiles::$changed_dockerfiles"
- name: Build and push Docker images
run: |
for dockerfile in ${{ steps.find-dockerfiles.outputs.changed_dockerfiles }}; do
folder=$(dirname $dockerfile)
docker build -t dinifarb/activemq:"$folder" "$folder"
docker push dinifarb/activemq:"$folder"
done