File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Build and Publish Docker Images
2
+
3
+ on :
4
+ push :
5
+ branches :
6
+ - master
7
+
8
+ jobs :
9
+ build :
10
+ runs-on : ubuntu-latest
11
+
12
+ steps :
13
+ - name : Checkout code
14
+ uses : actions/checkout@v4
15
+
16
+ - name : Get list of changed files
17
+ id : changed-files
18
+ uses : tj-actions/changed-files@v45
19
+ with :
20
+ json : ' true'
21
+
22
+ - name : Output changed files
23
+ run : |
24
+ echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
25
+
26
+ - name : Build and push Docker images
27
+ if : contains(steps.changed-files.outputs.all_changed_files, 'Dockerfile')
28
+ env :
29
+ REPOSITORY_OWNER : ${{ github.repository_owner }}
30
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
31
+ run : |
32
+ # Create a list of directories containing Dockerfiles
33
+ DOCKERFILE_DIRS=$(echo "${{ steps.changed-files.outputs.files }}" | grep 'Dockerfile' | xargs -I {} dirname {} | sort -u)
34
+
35
+ # Build and push Docker images for each directory containing Dockerfile
36
+ for DIR in $DOCKERFILE_DIRS; do
37
+ echo "Building Docker image in directory $DIR"
38
+ IMAGE_NAME="${REPOSITORY_OWNER}/$(basename $DIR):latest"
39
+ docker build -t $IMAGE_NAME $DIR
40
+ echo $GITHUB_TOKEN | docker login ghcr.io -u $REPOSITORY_OWNER --password-stdin
41
+ docker push $IMAGE_NAME
42
+ done
You can’t perform that action at this time.
0 commit comments