forked from localstack/localstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildspec.yml
More file actions
48 lines (44 loc) · 1.64 KB
/
buildspec.yml
File metadata and controls
48 lines (44 loc) · 1.64 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
version: 0.2
env:
variables:
DOCKER_BUILDKIT: 1
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR
- aws --version
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
- docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_PASSWORD}
- |
if echo "$CODEBUILD_WEBHOOK_HEAD_REF" | grep "refs/heads/"; then
export GIT_BRANCH=$(echo ${CODEBUILD_WEBHOOK_HEAD_REF#refs/heads/} | sed "s/\//\_/")
else
export GIT_BRANCH=$(echo ${CODEBUILD_WEBHOOK_HEAD_REF#refs/tags/}| sed "s/\//\_/")
fi
- |
if [ "$GIT_BRANCH" = "" ] ; then
GIT_BRANCH="$(git symbolic-ref HEAD --short 2>/dev/null)"
export GIT_BRANCH=$(echo "$GIT_BRANCH" | sed "s/\//\_/")
fi
- |
if [ "$GIT_BRANCH" = "" ] ; then
GIT_BRANCH="$(git branch -a --contains HEAD | sed -n 2p | awk '{ printf $1 }')";
GIT_BRANCH=${GIT_BRANCH#remotes/origin/};
export GIT_BRANCH=$(echo "$GIT_BRANCH" | sed "s/\//\_/")
fi
- echo "Branch name $GIT_BRANCH"
build:
commands:
- echo Build started on `date`
- echo Building the ECR image $REPOSITORY_URI:$GIT_BRANCH
- |
docker build \
--tag $REPOSITORY_URI:$GIT_BRANCH \
--tag $REPOSITORY_URI:latest \
-f Dockerfile .
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the ECR images $REPOSITORY_URI:$GIT_BRANCH
- docker push $REPOSITORY_URI:$GIT_BRANCH
- docker push $REPOSITORY_URI:latest