This repository has been archived by the owner on Aug 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from oneleif/develop
Develop
- Loading branch information
Showing
59 changed files
with
1,111 additions
and
894 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,105 @@ | ||
version: 2 | ||
version: 2.1 | ||
|
||
orbs: | ||
aws-code-deploy: circleci/aws-code-deploy@1.0.0 | ||
aws-cli: circleci/aws-cli@0.1.20 | ||
|
||
commands: | ||
deploy-to-aws: | ||
parameters: | ||
environment: | ||
type: string | ||
default: staging | ||
steps: | ||
- checkout | ||
- setup_remote_docker | ||
- run: | ||
name: Build docker release image | ||
command: | | ||
docker build -t oneleif-api:latest -f web.Dockerfile --build-arg env=<< parameters.environment >> . | ||
docker tag oneleif-api:latest oneleif-api:$CIRCLE_SHA1 | ||
- run: | ||
name: Create revision bundle | ||
command: | | ||
mkdir -p $BUNDLE_DIR | ||
docker save oneleif-api | gzip > $BUNDLE_DIR/oneleif-api.$CIRCLE_SHA1.tar.gz | ||
cp -r Deploy/* $BUNDLE_DIR/ | ||
- aws-cli/setup: | ||
aws-region: AWS_REGION | ||
- aws-code-deploy/push-bundle: | ||
application-name: $CODE_DEPLOY_APP_NAME | ||
bundle-bucket: $CODE_DEPLOY_BUNDLE_BUCKET | ||
bundle-key: << parameters.environment >>/$CIRCLE_SHA1 | ||
bundle-source: $BUNDLE_DIR | ||
- aws-code-deploy/deploy-bundle: | ||
application-name: $CODE_DEPLOY_APP_NAME | ||
bundle-bucket: $CODE_DEPLOY_BUNDLE_BUCKET | ||
bundle-key: << parameters.environment >>/$CIRCLE_SHA1 | ||
deployment-group: << parameters.environment >> | ||
|
||
jobs: | ||
linux: | ||
test: | ||
docker: | ||
- image: swift:4.1 | ||
- image: circleci/postgres:latest | ||
environment: | ||
POSTGRES_USER: oneleif | ||
POSTGRES_PASSWORD: root | ||
POSTGRES_DB: oneleif-testing | ||
POSTGRES_INITDB_ARGS: --auth-local password --auth-host password | ||
steps: | ||
- checkout | ||
- run: | ||
- run: | ||
name: Compile code | ||
command: swift build | ||
- run: | ||
- run: | ||
name: Run unit tests | ||
command: swift test | ||
|
||
linux-release: | ||
test-release: | ||
docker: | ||
- image: swift:4.1 | ||
steps: | ||
- checkout | ||
- run: | ||
- run: | ||
name: Compile code with optimizations | ||
command: swift build -c release | ||
|
||
build-and-deploy-staging: | ||
docker: | ||
- image: circleci/golang:latest | ||
steps: | ||
- deploy-to-aws: | ||
environment: staging | ||
|
||
build-and-deploy-production: | ||
docker: | ||
- image: circleci/golang:latest | ||
steps: | ||
- deploy-to-aws: | ||
environment: production | ||
|
||
workflows: | ||
version: 2 | ||
tests: | ||
build-and-deploy: | ||
jobs: | ||
- linux | ||
- linux-release | ||
- test | ||
- test-release | ||
- build-and-deploy-staging: | ||
requires: | ||
- test | ||
- test-release | ||
filters: | ||
branches: | ||
only: | ||
- develop | ||
context: oneleif-aws | ||
- build-and-deploy-production: | ||
requires: | ||
- test | ||
- test-release | ||
filters: | ||
branches: | ||
only: | ||
- master | ||
context: oneleif-aws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# For help completing this file, see the "AppSpec File Reference" in the | ||
# "CodeDeploy User Guide" at | ||
# https://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html | ||
version: 0.0 | ||
os: linux | ||
|
||
hooks: | ||
AfterInstall: | ||
- location: hooks/after.sh | ||
timeout: 300 | ||
runas: root | ||
ValidateService: | ||
- location: hooks/validate.sh | ||
timeout: 300 | ||
runas: root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
CONTAINER_NAME=oneleif-api-$DEPLOYMENT_GROUP_NAME | ||
IMAGE_FILE=$(find .. -name "oneleif-api.*.tar.gz" | head -n 1) | ||
NETWORK_NAME=olwebsite_default | ||
RESTART_POLICY=on-failure:10 | ||
IMAGE_NAME=oneleif-api | ||
ENV_FILE_PATH=/home/ubuntu/oneleif-env/$DEPLOYMENT_GROUP_NAME.env | ||
|
||
case $DEPLOYMENT_GROUP_NAME in | ||
"production") | ||
PORT=8080 | ||
;; | ||
"staging") | ||
PORT=8081 | ||
;; | ||
*) | ||
PORT=8888 | ||
;; | ||
esac | ||
|
||
echo "Deploying oneleif-api ($DEPLOYMENT_GROUP_NAME) on port $PORT..." | ||
|
||
# clean up | ||
docker stop $CONTAINER_NAME || true | ||
docker rm $CONTAINER_NAME || true | ||
|
||
# load revision image | ||
docker load -i $IMAGE_FILE | ||
|
||
# start new version | ||
docker run --env-file $ENV_FILE_PATH --name $CONTAINER_NAME --network $NETWORK_NAME --publish $PORT:80 --restart $RESTART_POLICY --detach $IMAGE_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
case $DEPLOYMENT_GROUP_NAME in | ||
"production") | ||
PORT=8080 | ||
;; | ||
"staging") | ||
PORT=8081 | ||
;; | ||
*) | ||
PORT=8888 | ||
;; | ||
esac | ||
|
||
# wait for application start on $PORT | ||
while ! bash -c "echo >/dev/tcp/localhost/$PORT"; do sleep 1; done | ||
|
||
HEALTH_CHECK_URL=localhost:$PORT/docs/index.html | ||
|
||
STATUS_CODE=$(curl --write-out %{http_code} --silent --output /dev/null $HEALTH_CHECK_URL) | ||
|
||
if [[ "$STATUS_CODE" -ne 200 ]] ; then | ||
echo "Status code is not 200 ($STATUS_CODE), deployment failed" | ||
exit 1 | ||
else | ||
echo "Request successful: $STATUS_CODE" | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.