forked from aws/sagemaker-xgboost-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_aws_docker.sh
executable file
·43 lines (31 loc) · 1.6 KB
/
build_aws_docker.sh
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
#!/bin/bash
# Define ECR Repository URL
ECR_URL="339712912845.dkr.ecr.ap-southeast-2.amazonaws.com" # infrastructure account
# Define Image Name
IMAGE_NAME="exfil-xgboost"
AWS_PROFILE="aws-infrastructure"
# Get the current Git commit hash to use as the image tag
IMAGE_TAG=$(git rev-parse HEAD)
echo "Building and running Docker container for commit: $IMAGE_TAG"
# Open Docker application
open -a Docker
pip install --upgrade pip
pip install "cython<3.0.0"
pip install -r requirements.txt --no-build-isolation
# Build the Docker image with the commit hash as a tag
docker buildx build --platform linux/amd64 -t xgboost-container-base:1.7-1-cpu-py3 -f docker/1.7-1/base/Dockerfile.cpu .
python3 setup.py bdist_wheel --universal
TOKEN=$(aws codeartifact get-authorization-token --domain unmand-infrastructure --domain-owner 339712912845 --query authorizationToken --output text --region ap-southeast-2 --profile $AWS_PROFILE)
docker buildx build \
--build-arg CODEARTIFACT_TOKEN=$TOKEN \
--build-arg CODEARTIFACT_DOMAIN_NAME="unmand-infrastructure" \
--build-arg CODEARTIFACT_DOMAIN_OWNER_ID="339712912845" \
--build-arg CODEARTIFACT_REPOSITORY_NAME="unmand-packages" \
--platform linux/amd64 \
-t ${IMAGE_NAME}:${IMAGE_TAG} \
-f docker/1.7-1/final/Dockerfile.cpu .
docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "${ECR_URL}/${IMAGE_NAME}:${IMAGE_TAG}"
# Login to AWS ECR and push the image
aws ecr get-login-password --region ap-southeast-2 --profile $AWS_PROFILE | docker login --username AWS --password-stdin $ECR_URL
docker push "${ECR_URL}/${IMAGE_NAME}:${IMAGE_TAG}"
echo "Pushed ${IMAGE_NAME}:${IMAGE_TAG} to AWS ECR"