-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildspec.yml
executable file
·76 lines (65 loc) · 3 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
version: 0.2
phases:
pre_build:
commands:
- echo Installing Miniconda...
- curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
- bash Miniconda3-latest-Linux-x86_64.sh -b -p $HOME/miniconda
- rm -f Miniconda3-latest-Linux-x86_64.sh
- echo 'export PATH="$HOME/miniconda/bin:$PATH"' >> $HOME/.bashrc
- source $HOME/.bashrc
- conda init bash
- source $HOME/.bashrc
- echo Creating a Python 3.10 environment...
- conda create -n myenv python=3.10 -y
- echo 'conda activate myenv' >> $HOME/.bashrc
- source $HOME/.bashrc
- echo Installing CI/CD Dependencies...
- pip install flake8 black pytest pytest-astropy pytest-cov
- pip install pytest pytest-astropy pytest-cov
- pip install -r requirements.dev.txt
- echo ________________________________
- echo Linting with Black...
- black --check --diff lambda_function
- echo ________________________________
- echo Linting with Flake...
- echo ________________________________
build:
commands:
- REGION=us-east-1
- echo Login to Private ECR $REGION
- aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin 351967858401.dkr.ecr.$REGION.amazonaws.com
- echo ________________________________
- ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output text)
- |
if git describe --tags --exact-match > /dev/null 2>&1; then
echo "This is a tag push event"
ECR_REPO="$ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/sdc_aws_sorting_lambda"
CDK_ENVIRONMENT=PRODUCTION
VERSION=`git describe --tags --exact-match`
elif [[ "${CDK_ENVIRONMENT}" == "PRODUCTION" ]]; then
echo "This is a production environment"
ECR_REPO="$ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/sdc_aws_sorting_lambda"
CDK_ENVIRONMENT=PRODUCTION
VERSION=`date -u +"%Y%m%d%H%M%S"`
else
echo "This is a development environment"
ECR_REPO="$ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/dev-sdc_aws_sorting_lambda"
CDK_ENVIRONMENT=DEVELOPMENT
VERSION=`date -u +"%Y%m%d%H%M%S"`
fi
- echo ________________________________
- echo Build Docker Image
- docker build --build-arg PUBLIC_ECR_REPO=$PUBLIC_ECR_REPO -t $ECR_REPO:latest lambda_function/.
- echo Tagging Docker Image...
- docker tag $ECR_REPO:latest $ECR_REPO:$VERSION
- echo Pushing the Docker image with Tags...
- docker push $ECR_REPO:latest
- docker push $ECR_REPO:$VERSION
- echo ________________________________
- echo Updating Deployment
- echo ________________________________
- aws codebuild start-build --project-name arn:aws:codebuild:us-east-2:$ACCOUNT_ID:project/build_sdc_aws_pipeline_architecture --environment-variables-override name=CDK_ENVIRONMENT,value=$CDK_ENVIRONMENT,type=PLAINTEXT
post_build:
commands:
- echo Build Successful - Lambda Successfully Built and Pushed to ECR