-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildspec.yml
31 lines (29 loc) · 1.4 KB
/
buildspec.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
version: 0.2
env:
variables:
ECR_REPO: "go"
FUNCTION_NAME: "demo"
phases:
install:
on-failure: ABORT
commands:
- nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2 &
- timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
pre_build:
on-failure: ABORT
commands:
- go mod download
- go env -w GOPROXY=direct
- go env -w CGO_ENABLED=0
- export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
- $(aws ecr get-login --no-include-email --region ${AWS_REGION})
build:
on-failure: ABORT
commands:
- echo "Building version ${CODEBUILD_BUILD_NUMBER} for account ${AWS_ACCOUNT_ID}"
- go build -ldflags="-w -s" -o main main.go
- docker build --tag ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPO}:${CODEBUILD_BUILD_NUMBER} .
post_build:
commands:
- docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPO}:${CODEBUILD_BUILD_NUMBER}
- echo "Lambda can now be updated from ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPO}:${CODEBUILD_BUILD_NUMBER} with something like" && echo "" && echo "aws lambda update-function-code --function-name ${FUNCTION_NAME} --image-uri ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPO}:${CODEBUILD_BUILD_NUMBER} --no-cli-pager"