You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
4.1 KiB
88 lines
4.1 KiB
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/**/*'
|
|
|