-
Notifications
You must be signed in to change notification settings - Fork 209
121 lines (121 loc) · 5.09 KB
/
deploy-k8s.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
name: deploy-k8s
run-name: ${{ github.actor }} send deploy EKS 🚀
on:
pull_request:
types: [opened, reopened, synchronize, edited, closed]
#push:
# branches:
# - FOUR-9465
workflow_dispatch:
env:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
aws-url: ${{ secrets.AWS_URL }}
pull_req_id: ${{github.event.pull_request.number}}
DATE: $(date -d '-1 day' '+%Y-%m-%d'|sed 's/-//g')
CI_PACKAGE_BRANCH: ${{github.event.pull_request.head.ref || 'next' }}
CI_PROJECT: ${{github.event.pull_request.head.repo.name || 'processmaker' }}
CI_PR_BODY: ${{ github.event_name == 'schedule' && 'ci:deploy' || github.event.pull_request.body }}
IMAGE_TAG: $(echo "$CI_PROJECT-$CI_PACKAGE_BRANCH" | sed "s;/;-;g")
DEPLOY: ${{ secrets.DEPLOY }}
GH_USER: ${{ secrets.GH_USER }}
GH_EMAIL: ${{ secrets.GH_EMAIL }}
GITHUB_COMMENT: ${{ secrets.GH_COMMENT }}
DOM_EKS: ${{ secrets.DOM_EKS }}
BASE: ${{ contains(github.event.pull_request.body, 'ci:next') && 'ci-base-php82' || 'ci-base' }}
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
imageEKS:
name: build-docker-image-EKS
if: contains(github.event.pull_request.body, 'ci:build-k8s')
runs-on: ubuntu-22.04
steps:
#- uses: actions/checkout@v3
- name: Clone repo K8S
run: |
git clone --depth 1 -b cicd2 "https://[email protected]/ProcessMaker/pm4-k8s-distribution.git" pm4-k8s-distribution
git clone --depth 1 "https://[email protected]/ProcessMaker/pm4-tools.git" pm4-k8s-distribution/images/pm4-tools
- name: Generate image EKS
run: |
cd pm4-k8s-distribution/images
bash build.k8s.sh $CI_PACKAGE_BRANCH ${{env.IMAGE_TAG}} $BASE
- name: List Images
run: |
docker images
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ env.aws-access-key-id }}
aws-secret-access-key: ${{ env.aws-secret-access-key }}
aws-region: ${{ env.aws-region }}
- name: Login to ECR
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/processmaker
- name: Push OpenSource Image to ECR
run: |
cd pm4-k8s-distribution
docker tag local/processmaker:${{env.IMAGE_TAG}} public.ecr.aws/processmaker/processmaker:${{env.IMAGE_TAG}}
docker push public.ecr.aws/processmaker/processmaker:${{env.IMAGE_TAG}}
- name: Push Enterprise Image to ECR
run: |
cd pm4-k8s-distribution
docker tag local/enterprise:${{env.IMAGE_TAG}} public.ecr.aws/processmaker/enterprise:${{env.IMAGE_TAG}}
docker push public.ecr.aws/processmaker/enterprise:${{env.IMAGE_TAG}}
deployEKS:
name: build-deploy-EKS
if: contains(github.event.pull_request.body, 'ci:build-k8s')
needs: imageEKS
runs-on: ubuntu-22.04
steps:
- name: Clone private repository
run: |
git clone --depth 1 -b main "https://[email protected]/ProcessMaker/argocd.git" argocd
cd argocd
- run: git config --global user.email $GH_EMAIL
- run: git config --global user.name $GH_USER
- name: Add instance EKS
run: |
cd argocd
deploy=$(echo -n ${{env.IMAGE_TAG}} | md5sum | head -c 10)
if ! echo $(ls ci/) | grep $deploy; then
echo "Creating Deploy :: $deploy"
cp template-argocd.yaml ci/ci-$deploy.yaml
cp template-db.yaml ./ci/job_database.yaml
sed -i "s/{{instance}}/ci-$deploy/" ./ci/ci-$deploy.yaml
sed -i "s/{{image}}/${{env.IMAGE_TAG}}/" ./ci/ci-$deploy.yaml
sed -i "s/{{instance}}/ci-$deploy/" ./ci/job_database.yaml
git status
git add .
git commit -m "Deploy CICD : ci-$deploy"
git push origin main
else
echo "Exist Deploy :: https://ci-$deploy$DOM_EKS"
fi
echo "INSTANCE_URL=https://ci-$deploy$DOM_EKS" >> "$GITHUB_ENV"
- name: Comment Instance
run: |
echo "Instance URL: '${INSTANCE_URL}'"
bash argocd/gh_comment.sh "$CI_PROJECT" "$pull_req_id"
deleteEKS:
name: Delete Instance
if: github.event.action == 'closed'
runs-on: ubuntu-22.04
steps:
- name: Clone private repository
run: |
git clone --depth 1 -b main "https://[email protected]/ProcessMaker/argocd.git" argocd
- run: git config --global user.email $GH_EMAIL
- run: git config --global user.name $GH_USER
- name: Remove instance EKS
run: |
cd argocd/ci/
deploy=$(echo -n ${{env.IMAGE_TAG}} | md5sum | head -c 10)
rm -rf ci-$deploy.yaml
git status
git add .
git commit -m "Delete Instance : ci-$deploy"
git push origin main