-
Notifications
You must be signed in to change notification settings - Fork 2
87 lines (76 loc) · 4.05 KB
/
build-test.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
name: build
on:
push:
# schedule:
# - cron: "0 5 * * *"
# This script is using PubSub+ Cloud deployment with following REST connection details in secrets
# PSCLOUD_USER, PSCLOUD_PASS, PSCLOUD_HOST - Without https://, PSCLOUD_VPN
# It is also using a GCP project and service account key provided in secrets
# GCP_PROJECT_ID, GCP_SA_KEY, GCP_SA_EMAIL
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 16
steps:
- uses: actions/checkout@v2
with:
ref: main
- name: Set env
run: |
TEST_PREFIX=gha-$(date +%s)
echo "TEST_PREFIX=$TEST_PREFIX" >> $GITHUB_ENV
echo "TEST_TOPIC=$TEST_PREFIX-topic" >> $GITHUB_ENV
echo "TEST_SUBSCRIPTION=$TEST_PREFIX-subsciption" >> $GITHUB_ENV
echo "TEST_SECRET=$TEST_PREFIX-rest-connection-secret" >> $GITHUB_ENV
echo "TEST_RUN_SERVICE=$TEST_PREFIX-connector-service" >> $GITHUB_ENV
echo "TEST_IMAGE=gcr.io/${{ secrets.GCP_PROJECT_ID }}/$TEST_PREFIX-connector" >> $GITHUB_ENV
echo "GOOGLE_CLOUD_REGION=us-east1" >> $GITHUB_ENV
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
- name: Create automation script
run: |
# Create connection secret
echo '{ "Username": "${{ secrets.PSCLOUD_USER }}", "Password": "${{ secrets.PSCLOUD_PASS }}", "Host": "https://${{ secrets.PSCLOUD_HOST }}:9443", "AuthScheme": "basic" }' > my-solace-rest-connection.txt
gcloud secrets create $TEST_SECRET --data-file="./my-solace-rest-connection.txt"
# deploy connector code
cd python-samples/run/gcp-pubsub-to-solace-pubsubplus
# Submit a build to GCP Container Registry using Google Cloud Build
gcloud builds submit --tag $TEST_IMAGE
# Deploy to Cloud Run
gcloud run deploy $TEST_RUN_SERVICE --image $TEST_IMAGE --no-allow-unauthenticated --platform managed --region $GOOGLE_CLOUD_REGION --set-secrets=SOLACE_BROKER_CONNECTION=$TEST_SECRET:latest
# Determine the run service endpoint
connector_url=`gcloud run services list | grep $TEST_RUN_SERVICE | awk '{print $4}'`
echo "Connector URL: $connector_url"
# Create test topic
gcloud pubsub topics create $TEST_TOPIC
# Create subscription
echo "Creating subscription"
echo gcloud pubsub subscriptions create $TEST_SUBSCRIPTION --topic=$TEST_TOPIC --push-endpoint=$connector_url --push-auth-service-account="${{secrets.GCP_SA_EMAIL}}"
gcloud pubsub subscriptions create $TEST_SUBSCRIPTION --topic=$TEST_TOPIC --push-endpoint=$connector_url --push-auth-service-account="${{secrets.GCP_SA_EMAIL}}"
# Get sdkperf test tool
curl -O https://sftp.solace.com/download/SDKPERF_C_LINUX64
tar -xvf SDKPERF_C_LINUX64
# Start to listen to messages in the background
pubSubTools/sdkperf_c -cip=tcps://${{ secrets.PSCLOUD_HOST }}:55443 -cu=${{ secrets.PSCLOUD_USER }}@${{ secrets.PSCLOUD_VPN }} -cp=${{ secrets.PSCLOUD_PASS }} -stl=">" -md > test.out &
echo "Started listening..."
sleep 10 # Wait a bit
pubSubTools/sdkperf_c -cip=tcps://${{ secrets.PSCLOUD_HOST }}:55443 -cu=${{ secrets.PSCLOUD_USER }}@${{ secrets.PSCLOUD_VPN }} -cp=${{ secrets.PSCLOUD_PASS }} -mn=10 -mr=0 -ptl=t1 -stl=t1 | grep "Total Messages"
# Publish to the topic
gcloud pubsub topics publish $TEST_TOPIC --message="Hello World"
# Check for messages at PubSub+
echo "Start dump"
cat test.out
echo "End dump"
# cat test.out | grep "Hello Wo"
- name: Delete test resources (Cleanup)
if: ${{ always() }}
run: |
gcloud secrets delete $TEST_SECRET --quiet
gcloud container images delete $TEST_IMAGE --quiet
gcloud run services delete $TEST_RUN_SERVICE --quiet --region $GOOGLE_CLOUD_REGION
gcloud pubsub topics delete $TEST_TOPIC --quiet
gcloud pubsub subscriptions delete $TEST_SUBSCRIPTION --quiet