forked from stampchain-io/stampchain.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildspec.yml
More file actions
67 lines (61 loc) · 3.11 KB
/
Copy pathbuildspec.yml
File metadata and controls
67 lines (61 loc) · 3.11 KB
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
version: 0.2
phases:
install:
runtime-versions:
docker: latest
commands:
- echo "Installing build dependencies..."
- yum -y install jq
pre_build:
commands:
- echo "Environment verification..."
- export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-us-east-1}
- export AWS_ACCOUNT_ID=${AWS_ACCOUNT_ID:-$(aws sts get-caller-identity --query Account --output text)}
- export ECR_REPOSITORY_NAME=${ECR_REPOSITORY_NAME:-btc-stamps-explorer}
- export BASE_REPOSITORY_NAME=${ECR_REPOSITORY_NAME}-base
- export ECR_URI="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com"
- echo "ECR URI $ECR_URI"
# Create repositories if they don't exist
- aws ecr describe-repositories --repository-names $ECR_REPOSITORY_NAME || aws ecr create-repository --repository-name $ECR_REPOSITORY_NAME
- aws ecr describe-repositories --repository-names $BASE_REPOSITORY_NAME || aws ecr create-repository --repository-name $BASE_REPOSITORY_NAME
# Login to ECR
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $ECR_URI
# Use the pre-cached base image from ECR to avoid Docker Hub rate limits
- echo "Using pre-cached base image from ECR to avoid Docker Hub rate limits..."
build:
commands:
- echo "Build started on $(date)"
# Modify Dockerfile to use our ECR cached base image before building
# Try ECR-cached base image, fall back to Docker Hub if not available
- DENO_VERSION=$(grep -oP 'FROM denoland/deno:alpine-\K[0-9.]+' Dockerfile | head -1)
- |
if [ -n "$DENO_VERSION" ]; then
echo "Detected Deno version: $DENO_VERSION"
BASE_TAG="alpine-${DENO_VERSION}-arm64"
# Check if cached base image exists in ECR
if aws ecr describe-images --repository-name $BASE_REPOSITORY_NAME --image-ids imageTag=${BASE_TAG} >/dev/null 2>&1; then
echo "Found cached base image ${BASE_TAG} in ECR, using it"
sed -i "s|FROM denoland/deno:alpine-${DENO_VERSION}|FROM $ECR_URI/$BASE_REPOSITORY_NAME:${BASE_TAG}|g" Dockerfile
else
echo "Cached base image ${BASE_TAG} not in ECR, pulling from Docker Hub"
echo "Caching base image for future builds..."
docker pull --platform=linux/arm64 denoland/deno:alpine-${DENO_VERSION} || true
docker tag denoland/deno:alpine-${DENO_VERSION} $ECR_URI/$BASE_REPOSITORY_NAME:${BASE_TAG} || true
docker push $ECR_URI/$BASE_REPOSITORY_NAME:${BASE_TAG} || true
fi
else
echo "Could not detect Deno version from Dockerfile, using Docker Hub directly"
fi
- docker build --platform=linux/arm64 -t $ECR_URI/$ECR_REPOSITORY_NAME:latest .
post_build:
commands:
- echo "Build completed on $(date)"
- docker push $ECR_URI/$ECR_REPOSITORY_NAME:latest
- echo '[{"name":"stamps-app-container","imageUri":"'$ECR_URI/$ECR_REPOSITORY_NAME:latest'"}]' > imagedefinitions.json
artifacts:
files:
- imagedefinitions.json
discard-paths: yes
cache:
paths:
- "/root/.docker/**/*"