-
Notifications
You must be signed in to change notification settings - Fork 98
285 lines (277 loc) · 12 KB
/
docker.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
name: Build Docker & cloud images
on:
workflow_dispatch:
inputs:
image_version:
description: "Docker image version"
required: true
staging:
description: "Staging build"
type: boolean
default: false
build_docker:
description: "Build docker images"
type: boolean
default: true
build_aws:
description: "Build AWS images"
type: boolean
default: true
build_azure:
description: "Build Azure images"
type: boolean
default: true
build_gcp:
description: "Build GCP images"
type: boolean
default: true
build_oci:
description: "Build OCI images"
type: boolean
default: true
build_nebius:
description: "Build Nebius images"
type: boolean
default: true
env:
PACKER_VERSION: "1.9.2"
BUILD_PREFIX: ${{ inputs.staging && format('stgn-{0}-', github.run_number) || '' }} # staging ? prefix : ''
jobs:
build-docker:
if: inputs.build_docker
defaults:
run:
working-directory: docker
runs-on: ubuntu-latest
strategy:
matrix:
python: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Build and upload to DockerHub
run: |
docker buildx build --platform linux/arm64/v8 --build-arg PYTHON=${{ matrix.python }} --push --provenance=false --tag dstackai/base:py${{ matrix.python }}-${{ inputs.image_version }}-arm64 -f cpu/Dockerfile .
docker buildx build --platform linux/amd64 --build-arg PYTHON=${{ matrix.python }} --push --provenance=false --tag dstackai/base:py${{ matrix.python }}-${{ inputs.image_version }}-amd64 -f cpu/Dockerfile .
docker manifest create dstackai/base:py${{ matrix.python }}-${{ inputs.image_version }} --amend dstackai/base:py${{ matrix.python }}-${{ inputs.image_version }}-arm64 --amend dstackai/base:py${{ matrix.python }}-${{ inputs.image_version }}-amd64
docker manifest push dstackai/base:py${{ matrix.python }}-${{ inputs.image_version }}
docker buildx build --platform linux/amd64 --build-arg PYTHON=${{ matrix.python }} --push --provenance=false --tag dstackai/base:py${{ matrix.python }}-${{ inputs.image_version }}-cuda-12.1 -f cuda/Dockerfile .
build-aws-images:
needs: build-docker
if: always() && inputs.build_aws && (needs.build-docker.result == 'success' || needs.build-docker.result == 'skipped')
defaults:
run:
working-directory: scripts/packer
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
strategy:
matrix:
variant: [ "", "-cuda" ]
steps:
- uses: actions/checkout@v3
- name: Download packer
run: |
wget https://releases.hashicorp.com/packer/${{ env.PACKER_VERSION }}/packer_${{ env.PACKER_VERSION }}_linux_amd64.zip
unzip packer_${{ env.PACKER_VERSION }}_linux_amd64.zip
chmod +x packer
- name: Run packer
run: |
./packer build -var-file=versions.json $PROD_VARS -var image_version=${{ inputs.image_version }} -var build_prefix=$BUILD_PREFIX aws-image${{ matrix.variant }}.json
env:
PROD_VARS: ${{ !inputs.staging && '-var-file=aws-vars-prod.json' || '' }} # production ? var-file : ''
build-azure-images:
needs: build-docker
if: always() && inputs.build_azure && (needs.build-docker.result == 'success' || needs.build-docker.result == 'skipped')
defaults:
run:
working-directory: scripts/packer
runs-on: ubuntu-latest
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
VERSION: ${{ github.run_number }}
strategy:
matrix:
variant: [ "", "-cuda", "-grid" ]
steps:
- uses: actions/checkout@v3
- uses: Azure/login@v1
name: Log in to az
with:
creds: '{"clientId":"${{ secrets.AZURE_CLIENT_ID }}","clientSecret":"${{ secrets.AZURE_CLIENT_SECRET }}","subscriptionId":"${{ secrets.AZURE_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.AZURE_TENANT_ID }}"}'
- name: Download packer
run: |
wget https://releases.hashicorp.com/packer/${{ env.PACKER_VERSION }}/packer_${{ env.PACKER_VERSION }}_linux_amd64.zip
unzip packer_${{ env.PACKER_VERSION }}_linux_amd64.zip
chmod +x packer
- name: Run packer
run: |
./packer build -var-file=versions.json -var image_version=${{ inputs.image_version }} -var build_prefix=$BUILD_PREFIX azure-image${{ matrix.variant }}.json
- name: Publish azure image
if: ${{ !inputs.staging }}
run: |
IMAGE_DEFINITION=${BUILD_PREFIX}dstack${{ matrix.variant }}-${{ inputs.image_version }}
IMAGE_NAME=${BUILD_PREFIX}dstack${{ matrix.variant }}-${{ inputs.image_version }}
../publish_azure_image.sh $IMAGE_DEFINITION $IMAGE_NAME
build-gcp-images:
needs: build-docker
if: always() && inputs.build_gcp && (needs.build-docker.result == 'success' || needs.build-docker.result == 'skipped')
defaults:
run:
working-directory: scripts/packer
runs-on: ubuntu-latest
strategy:
matrix:
variant: [ "", "-cuda" ]
permissions:
contents: 'read'
id-token: 'write'
steps:
- uses: actions/checkout@v3
- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
workload_identity_provider: 'projects/531508670106/locations/global/workloadIdentityPools/github-identity-pool/providers/github-id-provider'
service_account: 'github-actions@dstack.iam.gserviceaccount.com'
create_credentials_file: true
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
- name: Download packer
run: |
wget https://releases.hashicorp.com/packer/${{ env.PACKER_VERSION }}/packer_${{ env.PACKER_VERSION }}_linux_amd64.zip
unzip packer_${{ env.PACKER_VERSION }}_linux_amd64.zip
chmod +x packer
- name: Run packer
run: |
./packer build -var-file=versions.json -var image_version=${{ inputs.image_version }} -var build_prefix=$BUILD_PREFIX gcp-image${{ matrix.variant }}.json
- name: Publish images
run: |
IMAGE_VERSION=${IMAGE_VERSION//./-}
gcloud compute images add-iam-policy-binding ${BUILD_PREFIX}dstack${{ matrix.variant }}-$IMAGE_VERSION --member='allAuthenticatedUsers' --role='roles/compute.imageUser'
env:
IMAGE_VERSION: ${{ inputs.image_version }}
build-oci-images:
needs: build-docker
if: always() && inputs.build_oci && (needs.build-docker.result == 'success' || needs.build-docker.result == 'skipped')
runs-on: ubuntu-latest
env:
OCI_COMPARTMENT: ocid1.compartment.oc1..aaaaaaaaxu2uq64unfa2imwkp37icxqv6f7gwp2mczdt2mukuqbkauwqmbtq
OCI_SUBNET: ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaaewxkaqsmbi2tig5sfw4eexzo3mkb4zrpm4gwvfhqdddnxicxe4fa
OCI_AVAILABILITY_DOMAIN: kZql:EU-FRANKFURT-1-AD-3
OCI_REGION: eu-frankfurt-1
strategy:
matrix:
variant: [ "", "-cuda" ]
steps:
- uses: actions/checkout@v3
- name: Setup OCI config
run: |
mkdir ~/.oci
echo "$OCI_KEY_CONTENT" > ~/.oci/key.pem
echo [DEFAULT] > ~/.oci/config
echo region=$OCI_REGION >> ~/.oci/config
echo tenancy=$OCI_TENANCY >> ~/.oci/config
echo user=$OCI_USER >> ~/.oci/config
echo fingerprint=$OCI_FINGERPRINT >> ~/.oci/config
echo key_file=~/.oci/key.pem >> ~/.oci/config
env:
OCI_TENANCY: ${{ secrets.OCI_CLI_TENANCY }}
OCI_USER: ${{ secrets.OCI_CLI_USER }}
OCI_FINGERPRINT: ${{ secrets.OCI_CLI_FINGERPRINT }}
OCI_KEY_CONTENT: ${{ secrets.OCI_CLI_KEY_CONTENT }}
- name: Install packer
working-directory: scripts/packer
run: |
wget https://releases.hashicorp.com/packer/${{ env.PACKER_VERSION }}/packer_${{ env.PACKER_VERSION }}_linux_amd64.zip
unzip packer_${{ env.PACKER_VERSION }}_linux_amd64.zip
chmod +x packer
./packer plugins install github.com/hashicorp/oracle
- name: Run packer
working-directory: scripts/packer
run: |
./packer build \
-var-file=versions.json \
-var image_version=${{ inputs.image_version }} \
-var build_prefix=$BUILD_PREFIX \
-var oci_compartment_ocid=$OCI_COMPARTMENT \
-var oci_subnet_ocid=$OCI_SUBNET \
-var oci_availability_domain=$OCI_AVAILABILITY_DOMAIN \
oci-image${{ matrix.variant }}.json
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies for publishing
run: |
pip install .[oci]
- name: Copy image to target regions
if: ${{ !inputs.staging }}
run: |
python scripts/oci_image_tools.py copy \
--image ${BUILD_PREFIX}dstack${{ matrix.variant }}-${{ inputs.image_version }} \
--from $OCI_REGION \
--compartment $OCI_COMPARTMENT
- name: Publish image in OCI Marketplace
if: ${{ !inputs.staging }}
run: |
python scripts/oci_image_tools.py publish \
--image ${BUILD_PREFIX}dstack${{ matrix.variant }}-${{ inputs.image_version }} \
--compartment $OCI_COMPARTMENT \
--version ${{ inputs.image_version }} \
--description "Image for running workloads with dstack - https://dstack.ai/" \
--os "Ubuntu 22.04" \
--contact-name dstack \
--contact-email hello@dstack.ai
build-nebius-images:
needs: build-docker
if: always() && inputs.build_nebius && (needs.build-docker.result == 'success' || needs.build-docker.result == 'skipped')
defaults:
run:
working-directory: scripts/packer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get Nebius CLI
run: |
echo "CLI_VERSION=$CLI_VERSION"
curl -sSL https://storage.ai.nebius.cloud/ncp/install.sh | bash
echo "$HOME/nebius-cloud/bin" >> $GITHUB_PATH
env:
CLI_VERSION: 0.113.0+Nebius-AI
- name: Write Nebius credentials
uses: jsdaniell/create-json@v1.2.2
with:
name: "service_account.json"
json: ${{ secrets.NEBIUS_SERVICE_ACCOUNT }}
dir: "scripts/packer/"
- name: Setup Nebius profile
run: |
ncp config profile create packer
ncp config set endpoint api.ai.nebius.cloud:443
ncp config set service-account-key service_account.json
rm service_account.json
- name: Download packer
run: |
wget https://releases.hashicorp.com/packer/${{ env.PACKER_VERSION }}/packer_${{ env.PACKER_VERSION }}_linux_amd64.zip
unzip packer_${{ env.PACKER_VERSION }}_linux_amd64.zip
chmod +x packer
./packer init .
- name: Run packer (HCL2)
run: |
export PKR_VAR_nebius_token=$(ncp iam create-token)
./packer build -only yandex.nebius,yandex.nebius-cuda -var image_version=${{ inputs.image_version }} -var build_prefix=$BUILD_PREFIX .
env:
PKR_VAR_nebius_folder_id: ${{ secrets.NEBIUS_FOLDER_ID }}
PKR_VAR_nebius_subnet_id: ${{ secrets.NEBIUS_SUBNET_ID }}