1+ name : Docker Image Push (on commit and base image update)
2+
3+ on :
4+ push :
5+ branches : [ "master" ]
6+ schedule :
7+ - cron : " 15 4 */3 * *"
8+
9+ env :
10+ IMAGE_OWNER : kimbtechnologies
11+ IMAGE_NAME : ttt_sync
12+ BASE_IMAGE : kimbtechnologies/php_nginx:latest
13+
14+ jobs :
15+ build :
16+ runs-on : ubuntu-latest
17+ steps :
18+
19+ # Init and check
20+
21+ - name : Access to repository contents
22+ uses : actions/checkout@v3
23+
24+ - name : Check for new baseimage
25+ id : check
26+ uses : lucacome/docker-image-update-checker@v1
27+ with :
28+ base-image : " ${{env.BASE_IMAGE}}"
29+ image : " ${{env.IMAGE_OWNER}}/${{env.IMAGE_NAME}}:latest"
30+ if : github.event_name != 'push'
31+
32+ # Build image
33+
34+ - name : Build the Docker image
35+ run : docker build . --file "Dockerfile" --tag "$IMAGE_OWNER/$IMAGE_NAME:latest"
36+ if : ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }}
37+
38+ # Push latest tag
39+
40+ - name : Login to DockerHub
41+ uses : docker/login-action@v2
42+ with :
43+ username : ${{ secrets.DOCKER_USERNAME }}
44+ password : ${{ secrets.DOCKER_TOKEN }}
45+ if : ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }}
46+
47+ - name : Push to DockerHub
48+ run : docker push "$IMAGE_OWNER/$IMAGE_NAME:latest"
49+ if : ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }}
50+
51+ # Version tags to push
52+
53+ - name : Tag and push versions
54+ if : ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }}
55+ run : |
56+ cat VERSION | while read TAG; do
57+ if [[ $TAG =~ ^#.* ]] ; then
58+ echo "Skipping $TAG";
59+ else
60+ echo "Tagging image as $TAG and pushing";
61+ docker tag "$IMAGE_OWNER/$IMAGE_NAME:latest" "$IMAGE_OWNER/$IMAGE_NAME:$TAG"
62+ docker push "$IMAGE_OWNER/$IMAGE_NAME:$TAG"
63+ fi;
64+ done;
0 commit comments