-
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (86 loc) · 3.02 KB
/
api-dev-workflow.yaml
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: API dev
on:
push:
branches: [ "main" ]
paths:
- 'anoneko-adopt-api/**'
env:
IMAGE_NAME: ${{ github.repository }}
REGISTRY: docker.io
jobs:
build:
runs-on: ubuntu-latest
environment: DEV
outputs:
image_tag: ${{ steps.set-output.outputs.image_tag }}
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- name: Log into registry
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-
# Build and push Docker image with Buildx
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: "{{defaultContext}}:anoneko-adopt-api"
file: "docker/dev/Dockerfile"
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Set output
id: set-output
env:
DOCKER_METADATA: ${{ steps.meta.outputs.json }}
run: |
echo $DOCKER_METADATA | jq '.'
image_tag=$(echo "$DOCKER_METADATA" | jq -r '.tags[] | select(. | test("main-"))')
image_tag_sha=$(echo "$image_tag" | grep -o 'main-[a-f0-9]\+')
echo "image_tag=$image_tag_sha" >> $GITHUB_OUTPUT
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Print New Image tag
run: |
echo ${{ needs.build.outputs.image_tag }}
- name: Update tag in values.yaml
uses: mikefarah/[email protected]
with:
cmd: yq eval '.image.tag = "${{ needs.build.outputs.image_tag }}"' -i anoneko-adopt-api/chart/values.yaml
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: true
title: "Update Docker image in values.yaml for ArgoCD"
body: "This PR updates the image tag in `values.yaml`. Merge this PR to deploy the new image."
branch: helm/update-docker-image-tag
delete-branch: true
base: main