-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (61 loc) · 2.4 KB
/
Copy pathbuild-and-deploy.yml
File metadata and controls
72 lines (61 loc) · 2.4 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
name: Build & Push Docker Images
on:
push:
branches:
- main
env:
PROJECT_ID: general-theiagen
LOCATION: us
REPOSITORY: theiagen
permissions:
contents: read
id-token: write
jobs:
find-new-dockerfiles:
runs-on: ubuntu-latest
outputs:
json: ${{ steps.files.outputs.added_modified }}
steps:
- uses: actions/checkout@v4
- id: files
uses: Ana06/get-changed-files@v2.3.0
with:
format: "json"
filter: "*/*/Dockerfile"
- run: "echo ${{ steps.files.outputs.all }}"
build-and-push:
needs: find-new-dockerfiles
if: needs.find-new-dockerfiles.outputs.json != '[]'
runs-on: ubuntu-latest
strategy:
matrix:
added_modified: ${{ fromJson(needs.find-new-dockerfiles.outputs.json) }}
steps:
- name: Parse file paths
id: parse
run: |
echo "parsing ${{ matrix.added_modified }}"
tool=$(echo "${{ matrix.added_modified }}" | cut -f1 -d "/")
version=$(echo "${{ matrix.added_modified }}" | cut -f2 -d "/")
echo "found tool:version ${tool}:${version}"
echo "tool=$tool" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v3
with:
project_id: ${{ env.PROJECT_ID }}
workload_identity_provider: ${{ vars.WIP_PROVIDER }}
- name: Configure Docker for Artifact Registry
run: gcloud auth configure-docker ${{ env.LOCATION }}-docker.pkg.dev --quiet
- name: Build Docker image
run: |
docker build --target app \
-t ${{ env.LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ steps.parse.outputs.tool }}:${{ steps.parse.outputs.version }} \
-t ${{ env.LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ steps.parse.outputs.tool }}:latest \
./${{ steps.parse.outputs.tool }}/${{ steps.parse.outputs.version }}
- name: Push Docker image
run: |
docker push ${{ env.LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ steps.parse.outputs.tool }}:${{ steps.parse.outputs.version }}
docker push ${{ env.LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ steps.parse.outputs.tool }}:latest