1- name : Docker
1+ name : Publish Container Image
22
33on :
44 push :
5- # Publish `master` as Docker `latest` image.
6- branches :
7- - master
8-
95 # Publish `v1.2.3` tags as releases.
106 tags :
117 - v*
1410 pull_request :
1511
1612env :
17- # TODO: Change variable to your image's name.
18- IMAGE_NAME : image
13+ HUB_NAMESPACE : deck15
14+ REGISTRY : ghcr.io
15+ IMAGE_NAME : kubeval-tools
1916
2017jobs :
21- # Run tests .
18+ # Run build test .
2219 # See also https://docs.docker.com/docker-hub/builds/automated-testing/
2320 test :
2421 runs-on : ubuntu-latest
22+ permissions :
23+ contents : read
24+ packages : write
2525
2626 steps :
27- - uses : actions/checkout@v2
27+ - name : Checkout Repository
28+ uses : actions/checkout@v2
2829
29- - name : Run tests
30+ - name : Run Build
3031 run : |
3132 if [ -f docker-compose.test.yml ]; then
3233 docker-compose --file docker-compose.test.yml build
3839 # Push image to GitHub Packages.
3940 # See also https://docs.docker.com/docker-hub/builds/
4041 push :
41- # Ensure test job passes before pushing image.
42+ # Ensure build-image job passes before pushing image.
4243 needs : test
4344
4445 runs-on : ubuntu-latest
@@ -49,32 +50,61 @@ jobs:
4950 packages : write
5051
5152 steps :
52- - uses : actions/checkout@v2
53+ - name : Checkout the repo
54+ uses : actions/checkout@v2
5355
5456 - name : Build image
5557 run : docker build . --file Dockerfile --tag $IMAGE_NAME
5658
57- - name : Log into registry
58- run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
59-
60- - name : Push image
61- run : |
62- IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
63-
64- # Change all uppercase to lowercase
65- IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
66-
67- # Strip git ref prefix from version
68- VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
69-
70- # Strip "v" prefix from tag name
71- [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
72-
73- # Use Docker `latest` tag convention
74- [ "$VERSION" == "master" ] && VERSION=latest
75-
76- echo IMAGE_ID=$IMAGE_ID
77- echo VERSION=$VERSION
78-
79- docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
80- docker push $IMAGE_ID:$VERSION
59+ - name : Log in to the Container Registry
60+ uses : docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
61+ with :
62+ registry : ${{ env.REGISTRY }}
63+ username : ${{ github.actor }}
64+ password : ${{ secrets.GITHUB_TOKEN }}
65+
66+ - name : Log in to Docker Hub
67+ uses : docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
68+ with :
69+ username : ${{ secrets.DOCKER_USERNAME }}
70+ password : ${{ secrets.DOCKER_PASSWORD }}
71+
72+ - name : Extract metadata for Github Registry
73+ id : meta
74+ uses : docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
75+ with :
76+ images : |
77+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
78+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
79+ ${{ env.HUB_NAMESPACE }}/${{ env.IMAGE_NAME }}
80+ ${{ env.HUB_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
81+
82+ - name : Build and push Docker images
83+ uses : docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
84+ with :
85+ context : .
86+ push : true
87+ tags : ${{ steps.meta.outputs.tags }}
88+ labels : ${{ steps.meta.outputs.labels }}
89+
90+ # - name: Push image
91+ # run: |
92+ # IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
93+
94+ # # Change all uppercase to lowercase
95+ # IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
96+
97+ # # Strip git ref prefix from version
98+ # VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
99+
100+ # # Strip "v" prefix from tag name
101+ # [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
102+
103+ # # Use Docker `latest` tag convention
104+ # [ "$VERSION" == "master" ] && VERSION=latest
105+
106+ # echo IMAGE_ID=$IMAGE_ID
107+ # echo VERSION=$VERSION
108+
109+ # docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
110+ # docker push $IMAGE_ID:$VERSION
0 commit comments