-
Notifications
You must be signed in to change notification settings - Fork 2
137 lines (125 loc) · 4.85 KB
/
package.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Package
on:
workflow_dispatch:
inputs:
servicename:
description: 'Select service to build and deploy'
required: true
default: 'Aevatar.HttpApi.Host'
type: choice
options:
- Aevatar.Silo
- Aevatar.Developer.Host
env:
DOTNET_INSTALL_DIR: "./.dotnet"
concurrency:
group: workflow-${{ github.ref }}
cancel-in-progress: false
jobs:
publish:
runs-on: aismart-runner
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '9.0.x'
- name: Cache NuGet Packages
id: nuget-packages
uses: actions/cache@v4
env:
cache-name: nuget-package-cache
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.event.inputs.servicename }}
- name: List NuGet Packages
if: ${{ steps.nuget-packages.outputs.cache-hit == 'true' }}
continue-on-error: true
run: ls -lh ~/.nuget/packages
- run: dotnet publish src/${{ github.event.inputs.servicename}}/${{ github.event.inputs.servicename }}.csproj -o out/${{ github.event.inputs.servicename }}
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.inputs.servicename }}
path: out/${{ github.event.inputs.servicename }}
retention-days: 1
build-and-push-image:
needs: publish
runs-on: aismart-runner
permissions:
contents: read
outputs:
short_sha: ${{ steps.vars.outputs.short_sha }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "short_sha=$calculatedSha" >> "$GITHUB_OUTPUT"
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: ${{ github.event.inputs.servicename }}
path: out/${{ github.event.inputs.servicename }}
- name: Create image tag
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.REPOSITORY_REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ secrets.REPOSITORY }}/${{ github.event.inputs.servicename }}
tags: |
type=sha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
build-args: |
servicename=${{ github.event.inputs.servicename }}
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Determine hostType
id: determine_host_type
run: |
# Default hostType is undefined (-1), only set for specific applications
hostType="-1"
if [ "${{ github.event.inputs.servicename }}" = "Aevatar.Silo" ]; then
hostType="0"
elif [ "${{ github.event.inputs.servicename }}" = "Aevatar.Developer.Host" ]; then
hostType="1"
fi
echo "hostType=$hostType" >> $GITHUB_ENV
- name: Exit early for unsupported applications
if: env.hostType == '-1'
run: |
echo "Unsupported application: ${{ github.event.inputs.servicename }}. Skipping workflow."
exit 0
- name: Request token from auth-station
id: auth_token_request
run: |
response=$(curl -X POST "https://auth-station-staging.aevatar.ai/connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_id=${{ secrets.ECHOLISTEN_CLIENT_ID }}" \
--data-urlencode "client_secret=${{ secrets.ECHOLISTEN_CLIENT_SECRET }}" \
--data-urlencode "scope=Aevatar")
echo "Response: $response"
token=$(echo $response | jq -r '.access_token')
echo "access_token=$token" >> $GITHUB_ENV
- name: Conditionally Call UpdateDockerImage endpoint
run: |
echo "Calling UpdateDockerImage for hostType=${{ env.hostType }} with imageName=${{ steps.meta.outputs.tags }}"
curl -X 'POST' "https://station-staging.aevatar.ai/api/users/updateDockerImage?hostType=${{ env.hostType }}&imageName=$(echo '${{ steps.meta.outputs.tags }}' | sed 's/:/%3A/g')" \
-H "accept: */*" \
-H "Authorization: Bearer ${{ env.access_token }}" \
-H "X-Requested-With: XMLHttpRequest" \
-d ''
echo "Docker image updated successfully."