-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (141 loc) · 5.63 KB
/
test-on-pr.yaml
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Test on PR
on:
# For demo purposes only
workflow_dispatch:
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
DOCKER_BUILD_RECORD_RETENTION_DAYS: 1
GH_PG_USER: testuser
GH_PG_PASSWORD: testpassword
GH_PG_DB: testdb
services:
postgres:
image: postgres:15
options: >-
--health-cmd "pg_isready -U $POSTGRES_USER"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432/tcp
env:
POSTGRES_USER: ${{ env.GH_PG_USER }}
POSTGRES_PASSWORD: ${{ env.GH_PG_PASSWORD }}
POSTGRES_DB: ${{ env.GH_PG_DB }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install JRE
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
cache: maven
- name: Cache build artifacts
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-build-${{ github.sha }}
restore-keys:
${{ runner.os }}-build
- name: Run "unit" tests
run: ./mvnw -B test
env:
SPRING_FLYWAY_URL: jdbc:postgresql://localhost:${{ job.services.postgres.ports['5432'] }}/${{ env.GH_PG_DB }}
SPRING_R2DBC_URL: r2dbc:postgresql://localhost:${{ job.services.postgres.ports['5432'] }}/${{ env.GH_PG_DB }}
SPRING_R2DBC_USERNAME: ${{ env.GH_PG_USER }}
SPRING_R2DBC_PASSWORD: ${{ env.GH_PG_PASSWORD }}
- name: Authenticate on Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: projects/49535911505/locations/global/workloadIdentityPools/github-actions/providers/github-provider
service_account: [email protected]
- name: Set GKE credentials
uses: google-github-actions/get-gke-credentials@v2
with:
cluster_name: minimal-cluster
location: europe-west9
- name: Edit image tag with GitHub Run ID
run: (cd kubernetes && kustomize edit set image ghcr.io/ajavageek/vcluster-pipeline=:${{github.run_id}})
- name: Install vCluster
uses: loft-sh/setup-vcluster@main
with:
kubectl-install: false
- name: Create a vCluster
id: vcluster
run: time vcluster create vcluster-pipeline-${{github.run_id}}
- name: Connect to the vCluster
run: vcluster connect vcluster-pipeline-${{github.run_id}}
- name: Schedule PostgreSQL
run: helm install postgresql oci://registry-1.docker.io/bitnamicharts/postgresql --values kubernetes/values.yaml
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{github.run_id}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Set config map from values.yaml
run: |
kubectl create configmap postgres-config \
--from-literal="SPRING_FLYWAY_URL=jdbc:postgresql://$(yq .fullnameOverride kubernetes/values.yaml):5432/" \
--from-literal="SPRING_R2DBC_URL=r2dbc:postgresql://$(yq .fullnameOverride kubernetes/values.yaml):5432/" \
--from-literal="SPRING_R2DBC_USERNAME=$(yq .auth.user kubernetes/values.yaml)" \
--from-literal="SPRING_R2DBC_PASSWORD=$(yq .auth.password kubernetes/values.yaml)"
- name: Create Docker Registry Secret
run: |
kubectl create secret docker-registry github-docker-registry \
--docker-server=${{ env.REGISTRY }} --docker-email="[email protected]" \
--docker-username="${{ github.actor }}" --docker-password="${{ secrets.GITHUB_TOKEN }}" \
--dry-run=client -o yaml | kubectl apply -f -
- name: Deploy Kustomized manifest to Google Cloud
run: kubectl apply -k kubernetes
- name: Retrieve LoadBalancer external IP inside the vCluster
run: |
for i in {1..10}; do
EXTERNAL_IP=$(kubectl get service vcluster-pipeline -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
if [ -n "$EXTERNAL_IP" ]; then
break
fi
echo "Waiting for external IP..."
sleep 10
done
if [ -z "$EXTERNAL_IP" ]; then
echo "Error: External IP not assigned to the service" >&2
exit 1
fi
APP_BASE_URL="http://${EXTERNAL_IP}:8080"
echo "APP_BASE_URL=$APP_BASE_URL" >> $GITHUB_ENV
echo "External IP is $APP_BASE_URL"
- name: Run integration tests
run: ./mvnw -B verify -Dtest=SkipAll -Dsurefire.failIfNoSpecifiedTests=false
- name: Delete the vCluster
if: ${{ !cancelled() && steps.vcluster.conclusion == 'success' }}
run: vcluster delete vcluster-pipeline-${{github.run_id}}