generated from gouef/github-lib-template
-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (45 loc) · 2.12 KB
/
docker-push.yml
File metadata and controls
55 lines (45 loc) · 2.12 KB
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
45
46
47
48
49
50
51
52
53
54
55
name: Build and Push Docker image on Release
on:
workflow_run:
# workflows: ["Create Release"]
# types:
# - completed
jobs:
build:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Get repository name
id: repo_name
run: echo "REPO_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_OUTPUT
- name: Get latest release tag
id: get_tag
run: |
TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
echo "TAG=$TAG" >> $GITHUB_OUTPUT
- name: Build Docker image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ steps.repo_name.outputs.REPO_NAME }}:latest \
-t ${{ secrets.DOCKER_USERNAME }}/${{ steps.repo_name.outputs.REPO_NAME }}:${{ steps.get_tag.outputs.TAG }} .
- name: Push Docker image
run: |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ steps.repo_name.outputs.REPO_NAME }}:latest
docker push ${{ secrets.DOCKER_USERNAME }}/${{ steps.repo_name.outputs.REPO_NAME }}:${{ steps.get_tag.outputs.TAG }}
- name: Upload README to Docker Hub
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
run: |
REPO_NAME=${GITHUB_REPOSITORY#*/}
DESCRIPTION=$(jq -Rs '.' < README.md)
TOKEN=$(curl -s -H "Content-Type: application/json" \
-X POST -d '{"username": "'"$DOCKER_HUB_USERNAME"'", "password": "'"$DOCKER_HUB_TOKEN"'"}' \
https://hub.docker.com/v2/users/login/ | jq -r .token)
curl -X PATCH "https://hub.docker.com/v2/repositories/$DOCKER_HUB_USERNAME/$REPO_NAME/" \
-H "Authorization: JWT $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"full_description\": $DESCRIPTION}"