-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
108 lines (96 loc) · 4.09 KB
/
Copy pathaction.yml
File metadata and controls
108 lines (96 loc) · 4.09 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Deploy to Amazon EKS
description: 'Deploy to Amazon EKS'
inputs:
env-file: # id of input
description: '.env file separated by `;`'
required: true
firebase-json:
description: 'Firebase JSON'
required: true
aws-access-key:
description: 'AWS Access Key'
required: true
aws-secret-key:
description: 'AWS Secret Key'
required: true
aws-region:
description: 'AWS Region'
required: true
aws-eks-cluster-name:
description: 'AWS EKS Cluster Name'
required: true
kubernetes-subfolder:
description: 'Kubernetes Subfolder'
required: true
runs:
using: "composite"
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2
- name: Write env-file to a .env file
run: echo $ENV_FILE > .env && sed -i 's/\;/\n/g' .env
shell: bash
env:
ENV_FILE: ${{ inputs.env-file }}
- name: Write firebase-json to a firebase.json file
run: echo $FIREBASE_JSON > firebase.json
shell: bash
env:
FIREBASE_JSON: ${{ inputs.firebase-json }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ inputs.aws-access-key }}
aws-secret-access-key: ${{ inputs.aws-secret-key }}
aws-region: ${{ inputs.aws-region }}
- name: Use old version of kubectl
shell: bash
run: |
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.23.6/bin/linux/amd64/kubectl
mv ./kubectl ~/kubectl
chmod u+x ~/kubectl
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Create a ECR repo
shell: bash
run: |
aws ecr describe-repositories --repository-names ${{ github.event.repository.name }} || ( aws ecr create-repository --repository-name ${{ github.event.repository.name }} && aws ecr put-lifecycle-policy --repository-name ${{ github.event.repository.name }} --lifecycle-policy-text "{\"rules\":[{\"rulePriority\":1,\"description\":\"Keep last 5 images\",\"selection\":{\"tagStatus\":\"any\",\"countType\":\"imageCountMoreThan\",\"countNumber\":5},\"action\":{\"type\":\"expire\"}}]}" )
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ github.event.repository.name }}
IMAGE_TAG: ${{ github.sha }}.${{ github.run_number }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg ENV=$ENV .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
shell: bash
- name: Set up Kustomize
id: setup-kustomize
run: |-
curl -sfLo ~/kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
chmod u+x ~/kustomize
shell: bash
# NOTE: Deleting the jobs is not best idea, that is the current solution we are using
- name: Deploy to EKS
id: deploy-eks
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ github.event.repository.name }}
IMAGE_TAG: ${{ github.sha }}.${{ github.run_number }}
AWS_REGION: ${{ inputs.aws-region }}
AWS_EKS_CLUSTER_NAME: ${{ inputs.aws-eks-cluster-name }}
NAMESUFFIX: ${{ github.sha }}
run: |-
cd kubernetes/${{ inputs.kubernetes-subfolder }}
aws eks update-kubeconfig --name ${AWS_EKS_CLUSTER_NAME}
~/kustomize edit set image nginx=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
~/kubectl delete --ignore-not-found=true -f jobs.yaml
~/kustomize build . | ~/kubectl apply -f -
shell: bash