-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (74 loc) · 2.62 KB
/
Copy pathmain-docker.yml
File metadata and controls
81 lines (74 loc) · 2.62 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# This workflow will build and push a docker image to dockerhub
name: Main Docker
env:
IMAGE_NAME: datafog/datafog-api
MAJOR_VERSION: 1
on:
workflow_run:
workflows: ["Main and Dev CICD datafog-api app"]
branches:
- main
types:
- completed
jobs:
build-and-push-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
provenance: mode=max
sbom: true
tags: |
${{ steps.meta.outputs.tags }}
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ env.MAJOR_VERSION }}
platforms: linux/amd64,linux/arm64/v8
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: |
DATAFOG_DEPLOYMENT_TYPE=Docker,DATAFOG_API_VERSION=${{ env.IMAGE_NAME }}:${{ github.sha }}
- name: Update Docker Hub README
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
# Get the current README.md content
README_CONTENT=$(cat README.md)
# Define the Docker Hub API URL
API_URL="https://hub.docker.com/v2/repositories/datafog/datafog-api/"
# Create JSON payload
JSON_PAYLOAD=$(jq -n --arg msg "$README_CONTENT" '{"full_description": $msg}')
TOKEN=$(curl -s -H "Content-Type: application/json" \
-X POST \
-d "{\"username\": \"$DOCKER_USERNAME\", \"password\": \"$DOCKER_PASSWORD\"}" \
https://hub.docker.com/v2/users/login/ | jq -r .token)
curl -s -X PATCH \
-H "Content-Type: application/json" \
-H "Authorization: JWT $TOKEN" \
-d "$JSON_PAYLOAD" $API_URL