-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#163360183 Continuous deployment for develop-V2 (#174)
* ft(container): create a docker image - create a docker file that creates the application production environment [ Fixes #163360183] * chore(cleanup): remove unused commands - remove the copy:favicon command [ Fixes #163360183 ] * chore(node): move to node version 10 - use node version 10 in tests and deployment - add deployment for develop-v2 [ Fixes #163360183 ] * feat(deployment): add deployment script - Add a deployment script for the application - change the design configuration on the application to staging_v2 - Refactor the slack notification script [ Fixes #163360183 ] * chore(docker-image): opt for a lighter images - choose alpine image [ Fixes #163360183 ]
- Loading branch information
Showing
6 changed files
with
177 additions
and
8 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
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,18 @@ | ||
FROM node:dubnium-alpine | ||
|
||
LABEL AUTHOR="Crispus Kamau <crispus.kamau@andela.com>" | ||
LABEL application="soc-frontend" | ||
|
||
ENV NODE_PATH /usr/local/share/.config/yarn/global/node_modules/ | ||
|
||
RUN yarn global add express@4.16.2 morgan@1.9.1 | ||
|
||
WORKDIR /application | ||
|
||
COPY public /application | ||
|
||
COPY prodserver /application | ||
|
||
RUN chmod +x ./prodserver | ||
|
||
CMD ./prodserver 4000 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/bin/bash | ||
set -o errexit | ||
set -o pipefail | ||
|
||
DEFAULT_GOOGLE_CLUSTER_NAME=soc | ||
PROJECT_NAME=soc-frontend | ||
set_variables() { | ||
COMMIT_HASH=$(git rev-parse --short HEAD) | ||
|
||
case "$CIRCLE_BRANCH" in | ||
develop-V2) | ||
IMAGE_TAG="staging-v2-${COMMIT_HASH}" | ||
ENVIRONMENT=staging | ||
GOOGLE_COMPUTE_ZONE=${STAGING_ZONE} | ||
GOOGLE_CLUSTER_NAME=${STAGING_CLUSTER_NAME} | ||
DEPLOYMENT_NAME="staging-v2-${PROJECT_NAME}" | ||
export NODE_ENV=staging_v2 | ||
;; | ||
*) | ||
echo "Err: This branch should not deploy." | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
authorize_docker() { | ||
echo "====> Store Sand authenticate with service account" | ||
echo "$GCLOUD_SERVICE_KEY" | base64 --decode > "${HOME}"/gcloud-service-key.json | ||
|
||
|
||
echo "====> Login to docker registry" | ||
docker login -u _json_key -p "$(cat ${HOME}/gcloud-service-key.json)" https://gcr.io | ||
} | ||
|
||
deploy_image() { | ||
echo "====> Build application artifacts" | ||
yarn run build | ||
|
||
echo "====> Build docker image with built application artifacts" | ||
|
||
IMAGE="${DOCKER_REGISTRY}/${GOOGLE_PROJECT_ID}/${PROJECT_NAME}:${IMAGE_TAG}" | ||
|
||
docker build -t "$IMAGE" . | ||
|
||
docker push "$IMAGE" | ||
} | ||
|
||
install_google_cloud_sdk(){ | ||
echo "====> Installing google cloud sdk" | ||
echo "deb http://packages.cloud.google.com/apt cloud-sdk-jessie main" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list | ||
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - | ||
sudo apt-get update && sudo apt-get install kubectl google-cloud-sdk | ||
} | ||
|
||
configure_google_cloud_sdk() { | ||
echo "Configuring Google Cloud Sdk" | ||
gcloud auth activate-service-account --key-file="${HOME}"/gcloud-service-key.json | ||
gcloud --quiet config set project "${GOOGLE_PROJECT_ID}" | ||
gcloud --quiet config set compute/zone "${GOOGLE_COMPUTE_ZONE}" | ||
gcloud --quiet container clusters get-credentials "${GOOGLE_CLUSTER_NAME}" | ||
} | ||
|
||
deploy_to_kubernetes(){ | ||
echo "====> Prepare image for deployement" | ||
|
||
IMAGE="${DOCKER_REGISTRY}/${GOOGLE_PROJECT_ID}/${PROJECT_NAME}:${IMAGE_TAG}" | ||
echo "====> Deploying ${IMAGE} to ${DEPLOYMENT_NAME} in ${ENVIRONMENT} environment" | ||
|
||
|
||
kubectl set image deployment/${DEPLOYMENT_NAME} frontend="${IMAGE}" -n "${ENVIRONMENT}" | ||
|
||
if [ "$?" == "0" ]; then | ||
echo "Deployment completed succesfully" | ||
else | ||
echo "Failed to deploy ${IMAGE} to ${ENVIRONMENT} environment" | ||
fi | ||
|
||
} | ||
|
||
main() { | ||
set_variables | ||
authorize_docker | ||
deploy_image | ||
install_google_cloud_sdk | ||
configure_google_cloud_sdk | ||
deploy_to_kubernetes | ||
} | ||
|
||
main "$@" |
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,66 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o pipefail | ||
|
||
|
||
declare_env_variables() { | ||
|
||
# Declaring environment variables | ||
# | ||
# Some environment variables assigned externally are: | ||
# SLACK_CHANNEL_HOOK : This is the webhook for the Slack App where notifications will be sent from | ||
# DEPLOYMENT_CHANNEL : This is the channel on which the Slack notifications will be posted | ||
# Some template for the Slack message | ||
if [ ${CIRCLE_BRANCH} == "master" ]; then | ||
ENVIRONMENT="production-v2" | ||
else | ||
ENVIRONMENT="staging-v2" | ||
fi | ||
if [ "$1" == "success" ]; then | ||
MESSAGE_TEXT="The ${CIRCLE_BRANCH} branch has been deployed to the ${ENVIRONMENT} environment" | ||
MESSAGE_COLOR="good" | ||
|
||
fi | ||
if [ "$1" == "fail" ]; then | ||
MESSAGE_TEXT="Deployment to ${ENVIRONMENT} failed!!!" | ||
MESSAGE_COLOR="danger" | ||
fi | ||
|
||
COMMIT_LINK="https://github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/commit/${CIRCLE_SHA1}" | ||
IMG_TAG="$(git rev-parse --short HEAD)" | ||
CIRCLE_WORKFLOW_URL="https://circleci.com/workflow-run/${CIRCLE_WORKFLOW_ID}" | ||
SLACK_TEXT_TITLE="CircleCI Build #$CIRCLE_BUILD_NUM" | ||
SLACK_DEPLOYMENT_TEXT="Executed Git Commit <$COMMIT_LINK|${IMG_TAG}>: ${MESSAGE_TEXT}" | ||
} | ||
|
||
send_notification() { | ||
|
||
# Sending the Slack notification | ||
|
||
curl -X POST --data-urlencode \ | ||
"payload={ | ||
\"channel\": \"${DEPLOYMENT_CHANNEL}\", | ||
\"username\": \"JobNotification\", | ||
\"attachments\": [{ | ||
\"fallback\": \"CircleCI job notification\", | ||
\"color\": \"${MESSAGE_COLOR}\", | ||
\"author_name\": \"Branch: $CIRCLE_BRANCH by ${CIRCLE_USERNAME}\", | ||
\"author_link\": \"https://github.com/AndelaOSP/andela-societies-backend/tree/${CIRCLE_BRANCH}\", | ||
\"title\": \"${SLACK_TEXT_TITLE}\", | ||
\"title_link\": \"$CIRCLE_WORKFLOW_URL\", | ||
\"text\": \"${SLACK_DEPLOYMENT_TEXT}\" | ||
}] | ||
}" \ | ||
"${SLACK_CHANNEL_HOOK}" | ||
} | ||
|
||
main() { | ||
echo "Declaring environment variables" | ||
declare_env_variables "$@" | ||
|
||
echo "Sending notification" | ||
send_notification | ||
} | ||
|
||
main "$@" |