-
Notifications
You must be signed in to change notification settings - Fork 194
171 lines (158 loc) · 6.84 KB
/
build_push_img.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
169
170
171
name: Build and Push Marqo Docker Image
# TODO: Add concurrency for these tasks (https://s2search.atlassian.net/browse/MQ-274) (https://github.com/marqo-ai/marqo/pull/1024#discussion_r1841652402)
on:
workflow_call:
inputs:
marqo_ref:
description: 'Marqo branch-name, commit SHA or tag'
required: false
type: string
default: 'mainline'
push_to:
description: 'image destination. Options: "ECR" or "DockerHub" (Can be added in the future)'
required: true
type: string
default: 'ECR'
image_repo:
description: 'Image repository'
required: true
type: string
default: 'marqo'
image_tag:
description: 'Image tag'
required: true
type: string
outputs:
image_identifier:
# By image_identifier, we refer to the
# complete qualified image name with the image digest (i.e 424082663841.dkr.ecr.us-east-1.amazonaws.com/marqo-compatibility-tests@sha256:1234567890abcdef). image_identifier:
description: "The image_identifier (ex: 424082663841.dkr.ecr.us-east-1.amazonaws.com/marqo-compatibility-tests@sha256:1234567890abcdef)"
value: ${{ jobs.Docker-Build.outputs.image_identifier }}
workflow_dispatch: #for manual triggers
inputs:
marqo_ref:
description: 'Marqo branch-name, commit SHA or tag'
required: false
default: 'mainline'
push_to:
description: 'image destination. Options: "ECR", "DockerHub"'
required: true
options:
- ECR
- DockerHub
image_repo:
description: 'Image repository'
required: true
default: 'marqo'
image_tag:
description: 'Image tag'
required: true
jobs:
Start-Runner:
# on US-WEST-2, open source account
name: Start self-hosted EC2 runner
runs-on: ubuntu-latest
outputs:
label: ${{ steps.start-ec2-runner.outputs.label }}
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.MARQO_WORKFLOW_TESTS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.MARQO_WORKFLOW_TESTS_SECRET_ACCESS_KEY }}
#TODO: create a runner in us-east-1 and use it for the build https://github.com/marqo-ai/marqo/pull/1024#discussion_r1841644166
aws-region: us-west-2
- name: Start EC2 runner
id: start-ec2-runner
uses: machulav/ec2-github-runner@v2
with:
mode: start
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
# 200 GB amd64 image
ec2-image-id: ami-01accacd51bdde263
ec2-instance-type: t3.xlarge
subnet-id: subnet-038b1447ac3c97e7a
security-group-id: sg-094be521399e0d5ba
aws-resource-tags: > # optional, requires additional permissions
[
{"Key": "Name", "Value": "marqo-build-push-img-runner-${{ github.run_id }}"},
{"Key": "GitHubRepo", "Value": "${{ github.repository }}"},
{"Key": "WorkflowName", "Value": "${{ github.workflow }}"},
{"Key": "WorkflowRunId", "Value": "${{ github.run_id }}"},
{"Key": "WorlflowURL", "Value": "${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}"},
{"Key": "PoloRole", "Value": "testing"}
]
Docker-Build:
name: Build docker image
needs: Start-Runner # required to start the main job when the runner is ready
runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner
outputs:
image_identifier: ${{ steps.set-image-identifier-in-output.outputs.image_identifier }}
environment: marqo-build-environment
steps:
- name: Set input variables
id: set-inputs
run: |
echo "MARQO_REF=${{ inputs.marqo_ref || github.event.inputs.marqo_ref }}" >> $GITHUB_ENV
echo "PUSH_TO=${{ inputs.push_to || github.event.inputs.push_to }}" >> $GITHUB_ENV
echo "IMAGE_REPO=${{ inputs.image_repo || github.event.inputs.image_repo }}" >> $GITHUB_ENV
echo "IMAGE_TAG=${{ inputs.image_tag || github.event.inputs.image_tag }}" >> $GITHUB_ENV
- name: Checkout Marqo
uses: actions/checkout@v3
with:
repository: marqo-ai/marqo
ref: ${{ env.MARQO_REF }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to ECR
uses: docker/login-action@v2
if: env.PUSH_TO == 'ECR'
with:
registry: 424082663841.dkr.ecr.us-east-1.amazonaws.com
username: ${{ secrets.ECR_PUSHER_AWS_ACCESS_KEY_ID }}
password: ${{ secrets.ECR_PUSHER_AWS_SECRET_ACCESS_KEY }}
- name: Set registry and image repo
id: prepare
run: |
if [[ "${{ env.PUSH_TO }}" == "ECR" ]]; then
echo "registry=424082663841.dkr.ecr.us-east-1.amazonaws.com" >> $GITHUB_OUTPUT
else
echo "registry=marqoai" >> $GITHUB_OUTPUT
fi
- name: Build and push
id: build-and-push
uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.prepare.outputs.registry }}/${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}
- name: Output image_identifier
# By image_identifier, we refer to the complete qualified image name with the image digest (i.e 424082663841.dkr.ecr.us-east-1.amazonaws.com/marqo-compatibility-tests@sha256:1234567890abcdef)
id: set-image-identifier-in-output
run: |
echo "image_identifier=${{ steps.prepare.outputs.registry }}/${{ env.IMAGE_REPO }}@${{ steps.build-and-push.outputs.digest }}" >> $GITHUB_OUTPUT
Stop-Runner:
name: Stop self-hosted EC2 runner
needs:
- Start-Runner # required to get output from the start-runner job
- Docker-Build # required to wait when the main job is done
runs-on: ubuntu-latest
if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.MARQO_WORKFLOW_TESTS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.MARQO_WORKFLOW_TESTS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Stop EC2 runner
uses: machulav/ec2-github-runner@v2
with:
mode: stop
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}