This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildspec.yml
88 lines (81 loc) · 4.07 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
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
version: 0.2
env:
parameter-store:
DOCKER_HUB_USER: "/Casanode/DockerHub/User"
DOCKER_HUB_PASS: "/Casanode/DockerHub/Pass"
GITHUB_USER: "/Casanode/Git/User"
GITHUB_PASS: "/Casanode/Git/Pass"
phases:
pre_build:
commands:
- echo Installing source NPM dependencies...
- npm install
install:
commands:
# CodePipeline creates artifacts using zip format, which does not preserve the permissions/modes.
# we must reset permissions here
- chmod 755 pre-commit qemu-arm-static
build:
commands:
- echo Running tests
- if [ -z $CODECOV_TOKEN ]; then npm run test; else npm run coverage; fi
- echo Building the Docker image ...
# building
# Remove qemu-static if non-arm, or register
- |
if [ $ARCH != arm ]; then
rm qemu-arm-static
else
docker run --rm --privileged multiarch/qemu-user-static:register --reset
fi
- docker build . -f $DOCKERFILE -t $ORGANIZATION/$REPOSITORY:$ARCH
- docker tag $ORGANIZATION/$REPOSITORY:$ARCH $ORGANIZATION/$REPOSITORY:$ARCH
# Hacky way to determine what branch we are in. $CODEBUILD_SOURCE_VERSION is the git commit we are currently
# building. We search all local branches to get a list of branches that include that git commit. We return all
# alpha characters from the branch we are looking for.
#
# Ex.
# master => master
# release/1.0.0 => release
- masterBranchText=$(git branch --contains $CODEBUILD_SOURCE_VERSION | grep master | sed 's/[^a-zA-Z]//g')
- releaseBranchText=$(git branch --contains $CODEBUILD_SOURCE_VERSION | grep release | sed 's/[^a-zA-Z]//g')
- developBranchText=$(git branch --contains $CODEBUILD_SOURCE_VERSION | grep develop | sed 's/[^a-zA-Z]//g')
# push image to docker
- docker login --username=$DOCKER_HUB_USER --password=$DOCKER_HUB_PASS
# Since a git commit can be in multiple branches, we will start with master and work our way down. If a git commit
# exists in master, release, and develop, it really means we want to deploy master. Likewise, if a git commit exists
# in release and develop, we release want to deploy release.
#
# Public vs Private
# Casa Inc releases code publicly for various reasons. We also develop features in private before the public
# release. Historically we have used the private casacomputer organization on docker hub. We have since migrated
# to casanode for our public releases. We will support legacy nodes running on casacomputer until March 2020.
- |
if [ "$masterBranchText" = "master" ] && [ "$PUBLIC" = "false" ]; then
echo "pushing master branch to docker hub"
docker tag $ORGANIZATION/$REPOSITORY:$ARCH $ORGANIZATION/$REPOSITORY:$ARCH
docker push $ORGANIZATION/$REPOSITORY:$ARCH
elif [ "$masterBranchText" = "master" ] && [ "$PUBLIC" = "true" ]; then
echo "pushing master branch to docker hub"
docker tag $ORGANIZATION/$REPOSITORY:$ARCH $ORGANIZATION/$REPOSITORY:$ARCH
docker push $ORGANIZATION/$REPOSITORY:$ARCH
echo "pushing master branch to legacy docker hub"
docker tag casacomputer/$REPOSITORY:$ARCH casacomputer/$REPOSITORY:$ARCH
docker push casacomputer/$REPOSITORY:$ARCH
elif [ "$releaseBranchText" = "release" ] && [ "$PUBLIC" = "false" ]; then
echo "pushing release branch to docker hub"
docker tag $ORGANIZATION/$REPOSITORY:$ARCH $ORGANIZATION/$REPOSITORY:$ARCH-stage
docker push $ORGANIZATION/$REPOSITORY:$ARCH-stage
elif [ "$developBranchText" = "develop" ] && [ "$PUBLIC" = "false" ]; then
echo "pushing develop branch to docker hub"
docker tag $ORGANIZATION/$REPOSITORY:$ARCH $ORGANIZATION/$REPOSITORY:$ARCH-develop
docker push $ORGANIZATION/$REPOSITORY:$ARCH-develop
else
echo "docker image has been built, but not pushed to docker hub"
fi
post_build:
commands:
- echo Build completed on `date`
cache:
paths:
- 'node_modules/**/*'