diff --git a/README.md b/README.md index e256f39..46bccb7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,6 @@ # deploy_scripts Bash scripts used in automated deployments. -## Requirements -- AWS CLI -- kubectl - ## Usage These scripts are intended to be used in conjunction with AWS CodeDeploy to implement continuous deployment, and currently focus on Django and React applications. @@ -25,17 +21,5 @@ If you are using a subset of these scripts it may not be necessary to supply all of these environment variables. For example, when deploying a React application, it is not necessary to specify PYTHON_PATH. -### Additional Environment Variables for Container Deployments -The following environment variables are required for Container deploys. -- AWS_ACCOUNT_ID - the URL of the ECR Registry to which built images should be pushed -- AWS_REGION - the AWS Region which contains the ECR Registry -- AWS_ACCESS_KEY_ID - an AWS Access Key for a user with permissions to push to the ECR Registry -- AWS_SECRET_ACCESS_KEY - an AWS Secret Access Key for a user with permissions to push to the ECR Registry -- CLOUDFRONT_DISTRIBUTION_ID - an identifier for a CloudFront Distribution whose cache should be invalidadated (invalidate_cloudfront_cache.sh only) -- LAMBDA_FUNCTION_NAME - the name of an AWS Lambda function to which the image should be deployed (deploy_image_lambda.sh only) -- DEPLOYMENT_NAME - name for the deployed pod in Kubernetes (deploy_image_k8s.sh only) -- DOCKER_REPO - the name of the repository in the registry to which to push -- TIMESTAMP - current timestamp (should be generated and set once in a CI pipeline) - ## License This code is released under the MIT License. See `LICENSE.md` for more information. diff --git a/containers/add_tag_to_image.sh b/containers/add_tag_to_image.sh deleted file mode 100644 index 0dd5832..0000000 --- a/containers/add_tag_to_image.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -e - -REPO_NAME=$1 -CURRENT_TAG=$2 -NEW_TAG=$3 - -# make sure correct region is set -aws configure set default.region ${AWS_REGION} - -MANIFEST=$(aws ecr batch-get-image \ - --repository-name ${REPO_NAME} \ - --image-ids imageTag=${CURRENT_TAG} \ - --output json | jq --raw-output --join-output '.images[0].imageManifest') - -aws ecr put-image \ - --repository-name ${REPO_NAME} \ - --image-tag ${NEW_TAG} \ - --image-manifest "$MANIFEST" \ No newline at end of file diff --git a/containers/deploy_image_k8s.sh b/containers/deploy_image_k8s.sh deleted file mode 100644 index e077fc5..0000000 --- a/containers/deploy_image_k8s.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -e - -# Remove existing deployment -kubectl delete deployment ${DEPLOYMENT_NAME} - -# Apply deployments, configmaps and services -for TEMPLATE in k8s/*.yaml -do - kubectl apply -f TEMPLATE -done \ No newline at end of file diff --git a/containers/deploy_image_lambda.sh b/containers/deploy_image_lambda.sh deleted file mode 100644 index ae0b89a..0000000 --- a/containers/deploy_image_lambda.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -e - -REGISTRY_URL=${AWS_ECR_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com -SOURCE_IMAGE="${DOCKER_REPO}" -TARGET_IMAGE="${REGISTRY_URL}/${DOCKER_REPO}" -VERSION="${TIMESTAMP}-${TRAVIS_COMMIT}" -TARGET_IMAGE_VERSIONED="${TARGET_IMAGE}:${VERSION}" - -# make sure correct region is set -aws configure set default.region ${AWS_REGION} -# Log in to AWS -$(aws ecr get-login --no-include-email) - -aws lambda update-function-code \ - --function-name arn:aws:lambda:${AWS_REGION}:${AWS_LAMBDA_ACCOUNT_ID}:function:${LAMBDA_FUNCTION_NAME} \ - --image-uri ${TARGET_IMAGE_VERSIONED} \ No newline at end of file diff --git a/containers/install_kubectl.sh b/containers/install_kubectl.sh deleted file mode 100644 index bad3955..0000000 --- a/containers/install_kubectl.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -e - -# Download kubectl. Must match, within one minor version, the version of kubernetes. -curl -LO https://dl.k8s.io/release/v1.24.0/bin/linux/amd64/kubectl -chmod +x kubectl -mv ./kubectl /usr/local/bin/kubectl - -# Set up config. Assumes KUBE_CONFIG is a base_64 encoded kube-config file. -# See https://caveofcode.com/continuous-delivery-to-kubernetes-with-travis-ci/ -mkdir ${HOME}/.kube -echo "$KUBE_CONFIG" | base64 --decode > ${HOME}/.kube/config \ No newline at end of file diff --git a/containers/invalidate_cloudfront_cache.sh b/containers/invalidate_cloudfront_cache.sh deleted file mode 100644 index cb04aee..0000000 --- a/containers/invalidate_cloudfront_cache.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -e - -# make sure correct region is set -aws configure set default.region ${AWS_REGION} - -aws cloudfront create-invalidation \ - --distribution-id ${CLOUDFRONT_DISTRIBUTION_ID} \ - --paths "/*" \ No newline at end of file diff --git a/containers/push_image_to_ecr.sh b/containers/push_image_to_ecr.sh deleted file mode 100644 index c3f4531..0000000 --- a/containers/push_image_to_ecr.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -e - -DOCKER_REPO=$1 - -REGISTRY_URL=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com -SOURCE_IMAGE="${DOCKER_REPO}" -TARGET_IMAGE="${REGISTRY_URL}/${DOCKER_REPO}" - -# Construct latest tag -TARGET_IMAGE_LATEST="${TARGET_IMAGE}:latest" - -# Construct dev tag -TARGET_IMAGE_DEV="${TARGET_IMAGE}:dev" - -# Construct version number from datetime and commit hash -VERSION="${TIMESTAMP}-${TRAVIS_COMMIT}" -TARGET_IMAGE_VERSIONED="${TARGET_IMAGE}:${VERSION}" - -# make sure correct region is set -aws configure set default.region ${AWS_REGION} - -# Push image to ECR -################### - -# Log in to AWS -$(aws ecr get-login --no-include-email) - -# update latest version -docker tag ${SOURCE_IMAGE} ${TARGET_IMAGE_LATEST} -docker push ${TARGET_IMAGE_LATEST} - -# update dev version -docker tag ${SOURCE_IMAGE} ${TARGET_IMAGE_DEV} -docker push ${TARGET_IMAGE_DEV} - -# push new version -docker tag ${SOURCE_IMAGE} ${TARGET_IMAGE_VERSIONED} -docker push ${TARGET_IMAGE_VERSIONED} \ No newline at end of file diff --git a/create_apache_config.sh.deploy b/create_apache_config.sh.deploy deleted file mode 100644 index cb28b36..0000000 --- a/create_apache_config.sh.deploy +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -e - -cd ${ROOT_DIR} - -# Create Apache configs using mod_wsgi -if [ -f /etc/${APPLICATION_NAME}-${APPLICATION_PORT}/include.conf ] -then - env/bin/python manage.py runmodwsgi --setup-only --port=${APPLICATION_PORT} \ - --server-name=localhost \ - --server-root=/etc/${APPLICATION_NAME}-${APPLICATION_PORT} \ - --include-file=/etc/${APPLICATION_NAME}-${APPLICATION_PORT}/include.conf -else - env/bin/python manage.py runmodwsgi --setup-only --port=${APPLICATION_PORT} \ - --server-name=localhost \ - --server-root=/etc/${APPLICATION_NAME}-${APPLICATION_PORT} -fi diff --git a/deploy_package_lambda.sh b/deploy_package_lambda.sh deleted file mode 100644 index ec7621a..0000000 --- a/deploy_package_lambda.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -e - -LAMBDA_FUNCTION_NAME=$1 - -# make sure correct region is set -aws configure set default.region ${AWS_REGION} - -aws lambda update-function-code \ - --function-name arn:aws:lambda:${AWS_REGION}:${AWS_LAMBDA_ACCOUNT_ID}:function:${LAMBDA_FUNCTION_NAME} \ - --zip-file fileb://${LAMBDA_FUNCTION_NAME}.zip \ No newline at end of file diff --git a/make_zip_lambda.sh b/make_zip_lambda.sh deleted file mode 100755 index ee3c6b8..0000000 --- a/make_zip_lambda.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -LAMBDA_FUNCTION_NAME=$1 -LAMBDA_HANDLER_CODE=$2 - -# install requirements if necessary -if [ -f requirements.txt ]; -then - mkdir package - source ~/virtualenv/python${TRAVIS_PYTHON_VERSION}/bin/activate - pip install -r requirements.txt --target ./package - cd package - zip -r ../${LAMBDA_FUNCTION_NAME}.zip . - cd .. -fi - -# Copy handler code files -BASENAME=$(basename ${LAMBDA_HANDLER_CODE}) -cp ${LAMBDA_HANDLER_CODE} ${BASENAME} - -zip ${LAMBDA_FUNCTION_NAME}.zip ${BASENAME} diff --git a/make_zip_react.sh b/make_zip_react.sh deleted file mode 100755 index 4ea152f..0000000 --- a/make_zip_react.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -e - -ZIP_DIR=$1 -ZIP_NAME=$2 - -if [ ! -f $ZIP_DIR/$ZIP_NAME ]; then - - # copy appspec file - cp appspec.yml build/ - cp -r deploy_scripts/ build/ - # create zip file from build dir - zip -r $ZIP_NAME build - mkdir -p $ZIP_DIR - mv $ZIP_NAME $ZIP_DIR/$ZIP_NAME - -fi diff --git a/restart_apachectl.sh.deploy b/restart_apachectl.sh.deploy deleted file mode 100644 index 5e6bda5..0000000 --- a/restart_apachectl.sh.deploy +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -# restart apache, targetting app-specific configs -/etc/${APPLICATION_NAME}-${APPLICATION_PORT}/apachectl restart diff --git a/start_celery.sh b/start_celery.sh deleted file mode 100644 index 9763191..0000000 --- a/start_celery.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -# restart apache -sudo supervisorctl start celery celerybeat diff --git a/stop_celery.sh b/stop_celery.sh deleted file mode 100644 index 4e5b9fa..0000000 --- a/stop_celery.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -# restart apache -sudo supervisorctl stop celery celerybeat diff --git a/substitute_env.sh b/substitute_env.sh deleted file mode 100755 index b5f4f7f..0000000 --- a/substitute_env.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -e - -for TEMPLATE in ${APPLICATION_NAME}/config.py.deploy \ - .env.deploy \ - appspec.yml.deploy \ - deploy_scripts/*.deploy \ - k8s/*.deploy -do - if [[ -f "$TEMPLATE" ]]; then - echo "Replacing variables in $TEMPLATE" - envsubst < "$TEMPLATE" > `echo "$TEMPLATE" | sed -e 's/\(\.deploy\)*$//g'` - rm $TEMPLATE - fi -done - -chmod +x deploy_scripts/*.sh diff --git a/upload_file_to_s3.sh b/upload_file_to_s3.sh deleted file mode 100644 index cff1cbb..0000000 --- a/upload_file_to_s3.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -e - -FILE_NAME=$1 -BUCKET_NAME=$2 - -aws s3 cp ${FILE_NAME} s3://${BUCKET_NAME}/${FILE_NAME}