Repository navigation
117 lines (99 loc) · 4.34 KB
/
Copy pathdocker-image-eks.yml
File metadata and controls
117 lines (99 loc) · 4.34 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
109
110
111
112
113
114
115
116
117
name: Docker Image to k3s (test), then to EKS (prod)
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-login-push-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
-
name: 1 Build the Docker image (2 stages)
run: docker build . --build-arg PYPI_INDEX_URL=${{ secrets.PYPI_INDEX_URL }} --file Dockerfile --tag ${{ secrets.PYPI_HOST }}/default-docker-local/python-wallet-api:latest
-
name: 2 Docker Login (JFrog repo)
uses: docker/login-action@v1
with:
registry: ${{ secrets.PYPI_HOST }}
username: ${{ secrets.PYPI_USERNAME }}
password: ${{ secrets.PYPI_PASSWORD }}
-
name: 3 Push the image (JFrog repo)
run: docker push ${{ secrets.PYPI_HOST }}/default-docker-local/python-wallet-api:latest
-
name: 4 Do a test container run
run: docker run --name python-wallet-api ${{ secrets.PYPI_HOST }}/default-docker-local/python-wallet-api:latest &
-
name: 5 Do docker ps
run: docker ps
-
name: 6 Stop the container
run: docker stop python-wallet-api
k3s:
needs: [build-login-push-test]
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.PUBLIC_REPOS_TOKEN }}
- uses: nolar/setup-k3d-k3s@v1
-
name: Get k3s cluster info
run: |
kubectl cluster-info
kubectl get pods -n kube-system
kubectl get nodes
echo "current-context:" $(kubectl config current-context)
echo "environment-kubeconfig:" ${KUBECONFIG}
-
name: Deploy app & service to k3s
id: k3s-deploy
run: |
ls .
docker login -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} ${{ secrets.PYPI_HOST }}
docker pull ${{ secrets.PYPI_HOST }}/default-docker-local/python-wallet-api:latest
docker image tag ${{ secrets.PYPI_HOST }}/default-docker-local/python-wallet-api:latest python-wallet-api:k3s
docker images
docker save -o /tmp/python-wallet-api.tar python-wallet-api:k3s
k3d image import /tmp/python-wallet-api.tar
kubectl apply -f ./deployment.yml
kubectl get pods
while [[ $(kubectl get pods -l app=wallet-api -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "waiting for pod ..." && sleep 15 && kubectl describe pod wallet-api; done
-
name: Check step status
if: steps.k3s-deploy.outcome == 'failure'
run: exit 1
eks:
needs: [k3s]
if: ${{ (needs.k3s.result == 'success') && always() }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: 0 Prepare awscli
run: |
python -m pip install --upgrade pip
pip install awscli
- name: 1 Run aws configure
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws configure set default.region ${{ secrets.AWS_REGION }}
- uses: actions/checkout@v2
- name: 2 Set up cluster, then deploy app & service to EKS
run: |
aws eks --region ${{ secrets.AWS_REGION }} update-kubeconfig --name test
kubectl cluster-info
kubectl get nodes
kubectl get pods
kubectl apply -f ./deployment-eks.yml
kubectl get pods
while [[ $(kubectl get pods -l app=wallet-api -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "waiting for pod ..." && sleep 15 && kubectl describe pod wallet-api; done
# just for memo:
# put a secret creation command before apply -f if the secret is not exist in a fresh new cluster!
# kubectl create secret docker-registry artifactory --docker-server=https://${{ secrets.PYPI_HOST }} --docker-username=${{ secrets.PYPI_USERNAME }} --docker-password=${{ secrets.PYPI_PASSWORD}}
# for EKS:
# nothing to do with this if k3s! # kubectl create secret docker-registry regcred --docker-server=${{ secrets.PYPI_HOST }} --docker-username=${{ secrets.PYPI_USERNAME }} --docker-password=${{ secrets.PYPI_PASSWORD }}
# kubectl get pod -l app=wallet-api -ojson | jq .status.phase