Skip to content

Commit b4e2f07

Browse files
ci(e2e): 👷 docker and k3s test environment
Signed-off-by: Prashant Shahi <[email protected]>
1 parent bcef196 commit b4e2f07

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

.github/workflows/e2e-docker.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: e2e-docker
2+
3+
on:
4+
pull_request:
5+
types: [labeled]
6+
7+
jobs:
8+
9+
e2e-docker:
10+
runs-on: ubuntu-latest
11+
if: ${{ github.event.label.name == 'ok-to-test' }}
12+
env:
13+
DOCKER_TAG: pull-${{ github.event.number }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
18+
- name: Build Docker image
19+
run: docker build -t coolboi567/todo-flaskapp:$DOCKER_TAG .
20+
21+
- name: Deploy the FlaskApp
22+
run: docker-compose up -d --remove-orphans
23+
24+
- name: Get short commit SHA and display tunnel URL
25+
id: get-subdomain
26+
run: |
27+
subdomain="todo-flaskapp-docker-$(git rev-parse --short HEAD)"
28+
echo "URL for tunnelling: http://$subdomain.loca.lt"
29+
echo "::set-output name=subdomain::$subdomain"
30+
31+
- name: Start tunnel
32+
env:
33+
SUBDOMAIN: ${{ steps.get-subdomain.outputs.subdomain }}
34+
run: |
35+
npm install -g localtunnel
36+
port=$(docker port flask-app | grep -E '[0-9]{4,5}' -o | head -n 1)
37+
lt -p $port -s $SUBDOMAIN

.github/workflows/e2e-k3s.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: e2e-k3s
2+
3+
on:
4+
pull_request:
5+
types: [labeled]
6+
7+
jobs:
8+
9+
e2e-k3s:
10+
runs-on: ubuntu-latest
11+
if: ${{ github.event.label.name == 'ok-to-test' }}
12+
env:
13+
DOCKER_TAG: pull-${{ github.event.number }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
18+
- name: Build Docker image
19+
run: docker build -t coolboi567/todo-flaskapp:$DOCKER_TAG .
20+
21+
- name: Create a k3s cluster
22+
uses: AbsaOSS/k3d-action@v2
23+
with:
24+
cluster-name: "flaskapp"
25+
26+
- name: Inject the images to the cluster
27+
run: k3d image import coolboi567/todo-flaskapp:$DOCKER_TAG -c flaskapp
28+
29+
- name: Deploy the FlaskApp
30+
run: |
31+
# create flaskapp namespace
32+
kubectl create ns flaskapp
33+
34+
# installing FlaskApp using helm
35+
helm install my-release -n flaskapp ./helm \
36+
--wait \
37+
--timeout 10m0s \
38+
--set flaskapp.service.type=LoadBalancer \
39+
--set flaskapp.image.tag=$DOCKER_TAG
40+
41+
# get pods, services and the container images
42+
kubectl get pods -n flaskapp
43+
kubectl get svc -n flaskapp
44+
45+
- name: Get short commit SHA and display tunnel URL
46+
id: get-subdomain
47+
run: |
48+
subdomain="todo-flaskapp-k3s-$(git rev-parse --short HEAD)"
49+
echo "URL for tunnelling: http://$subdomain.loca.lt"
50+
echo "::set-output name=subdomain::$subdomain"
51+
52+
- name: Start tunnel
53+
env:
54+
SUBDOMAIN: ${{ steps.get-subdomain.outputs.subdomain }}
55+
run: |
56+
npm install -g localtunnel
57+
host=$(kubectl get svc -n flaskapp | grep flaskapp | tr -s ' ' | cut -d" " -f4)
58+
port=$(kubectl get svc -n flaskapp | grep flaskapp | tr -s ' ' | cut -d" " -f5 | cut -d":" -f1)
59+
lt -p $port -l $host -s $SUBDOMAIN

0 commit comments

Comments
 (0)