-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8_cicd copy.yml_back
90 lines (79 loc) · 2.8 KB
/
k8_cicd copy.yml_back
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
name: CI/CD
on:
push:
branches: [ master ]
paths-ignore:
- '.gitignore'
- '.dockerignore'
- 'README.md'
# paths:
# - '**.py'
pull_request:
branches: [ master ]
jobs:
ci:
runs-on: ubuntu-latest
outputs:
IMAGE_TAG: ${{ steps.set-var.outputs.IMAGE_TAG }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Set var
id: set-var
run: |
echo ::set-output name=ECR_REGISTRY::${{ steps.login-ecr.outputs.registry }}
echo ::set-output name=ECR_REPOSITORY::demo
echo ::set-output name=IMAGE_TAG::$(cat VERSION)
- name: Docker image Build
id: build-image
run: |
docker build \
-f Dockerfile \
-t ${{ steps.set-var.outputs.ECR_REGISTRY }}/${{ steps.set-var.outputs.ECR_REPOSITORY }}:${{ steps.set-var.outputs.IMAGE_TAG }} .
- name: Docker image Push
id: push-image
run: |
docker push ${{ steps.set-var.outputs.ECR_REGISTRY }}/${{ steps.set-var.outputs.ECR_REPOSITORY }}:${{ steps.set-var.outputs.IMAGE_TAG }}
cd:
needs: [ci]
runs-on: ubuntu-latest
steps:
- name: Checkout Target Repository
uses: actions/checkout@v2
with:
repository: iamchoiz/k8-cicd-argocd
path: deploy-k8s
- name: Replace image tag in helm values (LOCAL)
uses: mikefarah/yq@master
env:
IMAGE_TAG: ${{needs.ci.outputs.IMAGE_TAG}}
with:
cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'deploy-k8s/demo/values.yaml'
- name: Replace image tag in helm values (EKS)
uses: mikefarah/yq@master
env:
IMAGE_TAG: ${{needs.ci.outputs.IMAGE_TAG}}
with:
cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'deploy-k8s/demo/values-eks.yaml'
- name: Push helm repo
env:
token: ${{ secrets.GH_TOKEN }}
IMAGE_TAG: ${{needs.ci.outputs.IMAGE_TAG}}
run: |
cd deploy-k8s
git config --global user.email "dachan1207@gmail.com"
git config --global user.name "iamchoiz"
git add demo/values.yaml demo/values-eks.yaml;
git commit --message "Update demo image tag to $IMAGE_TAG";
git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | xargs -L1 git config --unset-all
git push --prune https://token:$token@github.com/iamchoiz/k8-cicd-argocd.git