-
Notifications
You must be signed in to change notification settings - Fork 812
/
buildspec_eks.yml
47 lines (41 loc) · 1.87 KB
/
buildspec_eks.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
version: 0.2
run-as: root
phases:
install:
commands:
- echo Installing app dependencies...
- curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.18.9/2020-11-02/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
- echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
- source ~/.bashrc
- echo 'Check kubectl version'
- kubectl version --short --client
- chmod +x eks_cicd/prereqs.sh
- sh eks_cicd/prereqs.sh
pre_build:
commands:
- echo Logging in to Amazon EKS...
- aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name $AWS_CLUSTER_NAME
- echo check config
- kubectl config view --minify
- echo check kubectl access
- kubectl get svc
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
- REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME
- docker pull $REPOSITORY_URI:$IMAGE_TAG
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build --cache-from $REPOSITORY_URI:$IMAGE_TAG -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
- echo Push the latest image to cluster
- kubectl apply -f eks_cicd/deployment.yaml
- kubectl rollout restart -f eks_cicd/deployment.yaml