55#
66
77# Name of this project
8- name : example- github-action-composite
8+ name : github-action-docker-promote
99
1010# Tags of this project
1111tags :
1212 - github-action
13+ - docker
1314
1415# Logo for this project
1516# logo: docs/logo.png
@@ -18,27 +19,37 @@ tags:
1819license : " APACHE2"
1920
2021# Canonical GitHub repo
21- github_repo : cloudposse/example- github-action-composite
22+ github_repo : cloudposse/github-action-docker-promote
2223
2324# Badges to display
2425badges :
2526 - name : " Latest Release"
26- image : " https://img.shields.io/github/release/cloudposse/example- github-action-composite .svg"
27- url : " https://github.com/cloudposse/example- github-action-composite /releases/latest"
27+ image : " https://img.shields.io/github/release/cloudposse/github-action-docker-promote .svg"
28+ url : " https://github.com/cloudposse/github-action-docker-promote /releases/latest"
2829 - name : " Slack Community"
2930 image : " https://slack.cloudposse.com/badge.svg"
3031 url : " https://slack.cloudposse.com"
3132
32- related : []
33+ related :
34+ - name : " github-action-docker-build-push"
35+ description : " Build Docker image and push it"
36+ url : " https://github.com/cloudposse/github-action-docker-build-push"
37+ - name : " github-action-docker-image-exists"
38+ description : " Check if docker image exists by pulling it"
39+ url : " https://github.com/cloudposse/github-action-docker-image-exists"
40+
3341
3442# Short description of this project
35- description : Template repository of composite GitHub Action
43+ description : Promote docker image
3644
3745introduction : |-
38- This is template repository to create composite GitHub Actions.
39- Feel free to use it as reference and starting point.
46+ Promote Docker image to specific tags provided explicitly or implicitly with
47+ [Docker Metadata action](https://github.com/marketplace/actions/docker-metadata-action)
4048
4149references :
50+ - name : " docker-metadata-action"
51+ description : " GitHub Action to extract metadata from Git reference and GitHub events."
52+ url : " https://github.com/marketplace/actions/docker-metadata-action"
4253 - name : " github-actions-workflows"
4354 description : " Reusable workflows for different types of projects"
4455 url : " https://github.com/cloudposse/github-actions-workflows"
@@ -48,6 +59,45 @@ references:
4859
4960# How to use this project
5061usage : |-
62+ ### Promote a docker image to specific tag
63+
64+ ```yaml
65+ name: Release
66+ on:
67+ release:
68+ types: [published]
69+
70+ permissions:
71+ id-token: write
72+ contents: write
73+
74+ jobs:
75+ promote:
76+ runs-on: ubuntu-latest
77+ steps:
78+ - name: Docker image promote
79+ uses: cloudposse/github-action-docker-promote@main
80+ id: promote
81+ with:
82+ registry: registry.hub.docker.com
83+ organization: ${{ github.event.repository.owner.login }}
84+ repository: ${{ github.event.repository.name }}
85+ login: ${{ secrets.DOCKERHUB_USERNAME }}
86+ password: ${{ secrets.DOCKERHUB_PASSWORD }}
87+ from: sha-${{ github.sha }}
88+ to: ${{ github.event.release.tag_name }}
89+ use_metadata: false
90+
91+ outputs:
92+ image: ${{ steps.promote.outputs.image }}
93+ tag: ${{ steps.promote.outputs.tag }}
94+ ```
95+
96+ ### Promote a docker image to tags detected from metadata
97+
98+ Promote action use [Docker Metadata action](https://github.com/marketplace/actions/docker-metadata-action) under the
99+ hood and can detect `to` tags based on Git reference and GitHub events.
100+
51101 ```yaml
52102 name: Pull Request
53103 on:
@@ -59,14 +109,70 @@ usage: |-
59109 context:
60110 runs-on: ubuntu-latest
61111 steps:
62- - name: Example action
63- uses: cloudposse/example-github-action-composite@main
64- id: example
112+
113+ - name: Checkout
114+ uses: actions/checkout@v3
115+ with:
116+ fetch-depth: 2
117+
118+ - name: Get previous commit
119+ id: prev-commit
120+ run: echo "sha=$(git rev-parse --verify HEAD^1)" >> $GITHUB_OUTPUT
121+
122+ - name: Docker image promote
123+ uses: cloudposse/github-action-docker-promote@main
124+ id: promote
65125 with:
66- param1: true
126+ registry: registry.hub.docker.com
127+ organization: ${{ github.event.repository.owner.login }}
128+ repository: ${{ github.event.repository.name }}
129+ login: ${{ secrets.DOCKERHUB_USERNAME }}
130+ password: ${{ secrets.DOCKERHUB_PASSWORD }}
131+ from: sha-${{ steps.prev-commit.outputs.sha }}
132+ use_metadata: true
133+
134+ outputs:
135+ image: ${{ steps.promote.outputs.image }}
136+ tag: ${{ steps.promote.outputs.tag }}
137+ ```
138+
139+ ### Promote a docker image with `from` fetched from metadata
140+
141+ If you skip `from` tag then it would be populated as SHA of the current commit in long format.
142+
143+ ```yaml
144+ name: Release
145+ on:
146+ release:
147+ types: [published]
148+
149+ permissions:
150+ id-token: write
151+ contents: write
152+
153+ jobs:
154+ promote:
155+ runs-on: ubuntu-latest
156+ steps:
157+ - name: Checkout
158+ uses: actions/checkout@v3
67159
160+ - name: Docker image promote
161+ uses: cloudposse/github-action-docker-promote@main
162+ id: promote
163+ with:
164+ registry: registry.hub.docker.com
165+ organization: ${{ github.event.repository.owner.login }}
166+ repository: ${{ github.event.repository.name }}
167+ login: ${{ secrets.DOCKERHUB_USERNAME }}
168+ password: ${{ secrets.DOCKERHUB_PASSWORD }}
169+ ## `from` is long SHA
170+ to: ${{ github.event.release.tag_name }}
171+ use_metadata: true
172+
68173 outputs:
69- result: ${{ steps.example.outputs.result1 }}
174+ image: ${{ steps.promote.outputs.image }}
175+ tag: ${{ steps.promote.outputs.tag }}
70176 ```
71177
72178include :
0 commit comments