forked from AlabamaWaterInstitute/CloudInfra
-
Notifications
You must be signed in to change notification settings - Fork 19
168 lines (159 loc) · 5.72 KB
/
docker_image_main_branch.yml
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Build and push final image
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
start-runner:
runs-on: ubuntu-latest
steps:
- name: start arm runner
uses: gagoar/invoke-aws-lambda@master
with:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
FunctionName: StartCirohRunner
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA') ||
(startsWith(github.ref, 'refs/heads/main') && github.event_name != 'pull_request')
- name: start x86 runner
uses: gagoar/invoke-aws-lambda@master
with:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
FunctionName: StartCirohX86Runner
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA') ||
(startsWith(github.ref, 'refs/heads/main') && github.event_name != 'pull_request')
- name: wait runner up
shell: bash
run: |
sleep 300
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA') ||
(startsWith(github.ref, 'refs/heads/main') && github.event_name != 'pull_request')
init:
needs: start-runner
runs-on: ${{ matrix.runner}}
strategy:
matrix:
runner: [ARM64, AMD64]
steps:
- name: clear docker cache
run: |
docker system prune -af
build:
needs: init
runs-on: ${{ matrix.runner}}
outputs: # Define job outputs
test-tag-name: ${{ steps.test-build.outputs.tag-name }}
push-tag-name: ${{ steps.push-build.outputs.tag-name }}
strategy:
matrix:
runner: [arm64, amd64]
steps:
- name: deploy
uses: actions/checkout@v2
- name: Build and test Docker image
id: test-build
uses: ./.github/action_templates/build-and-test
with:
docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }}
image-name: "ciroh-ngen-image"
dockerfile-name: "Dockerfile"
platform: ${{ matrix.runner}}
if: ${{ !startsWith(github.ref, 'refs/heads/main') }}
- name: Build and push Docker image
id: push-build
uses: ./.github/action_templates/build-and-push
with:
docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }}
image-name: "ciroh-ngen-image"
dockerfile-name: "Dockerfile"
platform: ${{ matrix.runner}}
if: startsWith(github.ref, 'refs/heads/main')
check_result:
needs: build
runs-on: ${{ matrix.runner}}
strategy:
matrix:
runner: [ARM64, AMD64]
outputs:
output1: ${{ steps.step1.outputs.result }}
steps:
- id: step1
run: echo "result=success" >> "$GITHUB_OUTPUT"
create-manifest:
needs: [check_result, build]
runs-on: ARM64
steps:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: awiciroh
password: ${{ secrets.DOCKER_AUTH_TOKEN }}
- name: Create and push manifest
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "Using push tag (main branch)"
TAG_NAME="${{ needs.build.outputs.push-tag-name }}"
else
echo "Using test tag (non-main branch)"
TAG_NAME="${{ needs.build.outputs.test-tag-name }}"
if [[ -z "${TAG_NAME}" ]]; then
echo "Error: test tag is empty"
exit 1
fi
fi
echo "Creating manifest with TAG_NAME: ${TAG_NAME}"
# Remove existing manifest if exists
docker manifest rm awiciroh/ciroh-ngen-image:${TAG_NAME} || true
docker manifest create --amend awiciroh/ciroh-ngen-image:${TAG_NAME} \
awiciroh/ciroh-ngen-image:${TAG_NAME}-arm64 \
awiciroh/ciroh-ngen-image:${TAG_NAME}-amd64
docker manifest push awiciroh/ciroh-ngen-image:${TAG_NAME}
slack:
runs-on: ARM64
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA') ||
(startsWith(github.ref, 'refs/heads/main') && github.event_name != 'pull_request')
needs: [build, check_result,create-manifest]
env:
OUTPUT: ${{needs.check_result.outputs.output1}}
steps:
- name: Set env JOBSTATUS
run: |
echo "$OUTPUT"
if [[ "success" = "$OUTPUT" ]]
then
echo "JOBSTATUS=success" >> "$GITHUB_ENV"
else
echo "JOBSTATUS=failure" >> "$GITHUB_ENV"
fi
- run: echo "$JOBSTATUS"
- name: deploy
uses: actions/checkout@v2
- name: Publish slack message
if: always()
uses: ./.github/action_templates/slack
with:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
job-status: ${{ env.JOBSTATUS }}
pull_request_url: ${{ github.event.pull_request.html_url }}
head_commit_url: ${{ github.event.head_commit.url }}
stop-runner:
needs: slack
runs-on: ubuntu-latest
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA') ||
(startsWith(github.ref, 'refs/heads/main') && github.event_name != 'pull_request')
steps:
- name: stop arm runner
uses: gagoar/invoke-aws-lambda@master
with:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
FunctionName: StopCirohRunner
- name: stop x86 runner
uses: gagoar/invoke-aws-lambda@master
with:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
FunctionName: StopCirohX86Runner