From 347842cba8b65890ec5612152d71d1a60523ef66 Mon Sep 17 00:00:00 2001 From: Will Smith Date: Wed, 13 Dec 2023 14:34:43 -0800 Subject: [PATCH] Build and use sample images in PR (#898) * Working on building sample images Signed-off-by: willdavsmith * Working on building sample images Signed-off-by: willdavsmith * Working on building sample images Signed-off-by: willdavsmith * Working on building sample images Signed-off-by: willdavsmith * Working on building sample images Signed-off-by: willdavsmith * Working on building sample images Signed-off-by: willdavsmith * Working on building sample images Signed-off-by: willdavsmith * Working on building sample images Signed-off-by: willdavsmith * Working on building sample images Signed-off-by: willdavsmith * Working on building sample images Signed-off-by: willdavsmith * Working on building sample images Signed-off-by: willdavsmith --------- Signed-off-by: willdavsmith --- .github/workflows/build.yaml | 15 ++------------- .github/workflows/test.yaml | 36 ++++++++++++++++++++++++++++++------ samples/aws-sqs/sqs.bicep | 6 ++++-- samples/aws/awss3.bicep | 4 +++- samples/dapr/dapr.bicep | 7 +++++-- samples/demo/app.bicep | 4 +++- samples/volumes/app.bicep | 4 +++- 7 files changed, 50 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9e055d42..96c3e135 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -6,25 +6,14 @@ on: branches: - edge - v*.* - pull_request: - types: [opened, synchronize, reopened, closed] - branches: - - edge - - v*.* - -concurrency: - group: build-${{ github.event.pull_request.number || github.sha }} - cancel-in-progress: true env: - VERSION: ${{ github.event.pull_request.number || 'latest' }} - # Use ghcr.io/radius-project/dev for PR build. Otherwise, use ghcr.io/radius-project. - CONTAINER_REGISTRY: ${{ github.event.pull_request.number && 'ghcr.io/radius-project/dev' || 'ghcr.io/radius-project' }} + VERSION: 'latest' + CONTAINER_REGISTRY: 'ghcr.io/radius-project' jobs: build-ghcr: name: Build and push sample images to GHCR - if: github.event.action != 'closed' runs-on: ubuntu-latest permissions: contents: read diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4d723234..42d5714c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,23 +37,32 @@ jobs: app: demo env: default path: ./samples/demo/app.bicep - args: --application demo + deployArgs: --application demo -p image=sampleregistry:5000/samples/demo + exposeArgs: --application demo uiTestFile: tests/demo/demo.app.spec.ts port: 3000 container: demo enableDapr: false + images: samples/demo + directories: samples/demo/ - name: dapr runOnPullRequest: true app: dapr env: default path: ./samples/dapr/dapr.bicep + deployArgs: -p frontendImage=sampleregistry:5000/samples/dapr-frontend -p backendImage=sampleregistry:5000/samples/dapr-backend enableDapr: true + images: samples/dapr-frontend,samples/dapr-backend + directories: samples/dapr/ui/,samples/dapr/nodeapp/ - name: volumes runOnPullRequest: true app: myapp env: default path: ./samples/volumes/app.bicep + deployArgs: -p image=sampleregistry:5000/samples/volumes enableDapr: false + images: samples/volumes + directories: samples/volumes/ - name: eshop-containers runOnPullRequest: true app: eshop @@ -169,11 +178,26 @@ jobs: timeout-minutes: 60 continue-on-error: false - name: Download k3d - if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential != 'aws' + if: steps.gen-id.outputs.RUN_TEST == 'true' run: wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash - name: Create k3d cluster - if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential != 'aws' - run: k3d cluster create --agents 2 -p "80:80@loadbalancer" --k3s-arg "--disable=traefik@server:0" + if: steps.gen-id.outputs.RUN_TEST == 'true' + run: k3d cluster create --agents 2 -p "80:80@loadbalancer" --k3s-arg "--disable=traefik@server:0" --registry-create sampleregistry:51351 + - name: Build images + if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.images != '' + run: | + # split images and directories into arrays + IFS=',' read -ra images <<< "${{ matrix.images }}" + IFS=',' read -ra directories <<< "${{ matrix.directories }}" + echo "Building images: $images" + echo "Directories: $directories" + for index in "${!images[@]}"; do + image=${images[$index]} + directory=${directories[$index]} + echo "Building image $image from directory $directory" + docker build -t localhost:51351/$image:latest $directory + docker push localhost:51351/$image:latest + done - name: Install Dapr if: steps.gen-id.outputs.RUN_TEST == 'true' && steps.gen-id.outputs.ENABLE_DAPR == 'true' run: | @@ -228,7 +252,7 @@ jobs: # Deploy application and run tests - name: Deploy app if: steps.gen-id.outputs.RUN_TEST == 'true' - run: rad deploy ${{ matrix.path }} ${{ matrix.args }} + run: rad deploy ${{ matrix.path }} ${{ matrix.deployArgs }} - name: Wait for all pods to be ready if: steps.gen-id.outputs.RUN_TEST == 'true' id: wait-for-pods @@ -241,7 +265,7 @@ jobs: id: run-playwright-test run: | if [[ "${{ matrix.container }}" != "" ]]; then - rad resource expose containers ${{ matrix.container }} ${{ matrix.args }} --port ${{ matrix.port }} & + rad resource expose containers ${{ matrix.container }} ${{ matrix.exposeArgs }} --port ${{ matrix.port }} & else endpoint="$(rad app status -a ${{ matrix.app }} | sed 's/ /\n/g' | grep http)" echo "Endpoint: $endpoint" diff --git a/samples/aws-sqs/sqs.bicep b/samples/aws-sqs/sqs.bicep index 5902a0a6..5bc7c125 100644 --- a/samples/aws-sqs/sqs.bicep +++ b/samples/aws-sqs/sqs.bicep @@ -10,6 +10,8 @@ param aws_access_key_id string param aws_secret_access_key string param aws_region string +param image string = 'ghcr.io/radius-project/samples/aws-sqs-sample:latest' + var aws_credential = { AWS_ACCESS_KEY_ID: aws_access_key_id AWS_SECRET_ACCESS_KEY: aws_secret_access_key @@ -44,7 +46,7 @@ resource producer 'Applications.Core/containers@2023-10-01-preview' = { }, aws_credential ) - image: 'ghcr.io/radius-project/samples/aws-sqs-sample:latest' + image: image } } } @@ -61,7 +63,7 @@ resource consumer 'Applications.Core/containers@2023-10-01-preview' = { }, aws_credential ) - image: 'ghcr.io/radius-project/samples/aws-sqs-sample:latest' + image: image } } } diff --git a/samples/aws/awss3.bicep b/samples/aws/awss3.bicep index 7e84671d..9f01ac82 100644 --- a/samples/aws/awss3.bicep +++ b/samples/aws/awss3.bicep @@ -13,6 +13,8 @@ param aws_secret_access_key string param aws_region string +param image string = 'ghcr.io/radius-project/samples/aws:latest' + resource s3 'AWS.S3/Bucket@default' = { alias: bucket properties: { @@ -39,7 +41,7 @@ resource frontend 'Applications.Core/containers@2023-10-01-preview' = { AWS_SECRET_ACCESS_KEY: aws_secret_access_key AWS_DEFAULT_REGION: aws_region } - image: 'ghcr.io/radius-project/samples/aws:latest' + image: image } } } diff --git a/samples/dapr/dapr.bicep b/samples/dapr/dapr.bicep index 978c26fe..60004376 100644 --- a/samples/dapr/dapr.bicep +++ b/samples/dapr/dapr.bicep @@ -6,6 +6,9 @@ param environment string @description('Specifies Kubernetes namespace for redis.') param namespace string = 'default' +param frontendImage string = 'ghcr.io/radius-project/samples/dapr-frontend:latest' +param backendImage string = 'ghcr.io/radius-project/samples/dapr-backend:latest' + resource app 'Applications.Core/applications@2023-10-01-preview' = { name: 'dapr' properties: { @@ -18,7 +21,7 @@ resource backend 'Applications.Core/containers@2023-10-01-preview' = { properties: { application: app.id container: { - image: 'ghcr.io/radius-project/samples/dapr-backend:latest' + image: backendImage ports: { web: { containerPort: 3000 @@ -45,7 +48,7 @@ resource frontend 'Applications.Core/containers@2023-10-01-preview' = { properties: { application: app.id container: { - image: 'ghcr.io/radius-project/samples/dapr-frontend:latest' + image: frontendImage env: { CONNECTION_BACKEND_APPID: backend.name ASPNETCORE_URLS: 'http://*:8080' diff --git a/samples/demo/app.bicep b/samples/demo/app.bicep index 9ef4a41c..8eabe9dd 100644 --- a/samples/demo/app.bicep +++ b/samples/demo/app.bicep @@ -3,12 +3,14 @@ import radius as radius param application string param environment string +param image string = 'ghcr.io/radius-project/samples/demo:latest' + resource demo 'Applications.Core/containers@2023-10-01-preview' = { name: 'demo' properties: { application: application container: { - image: 'ghcr.io/radius-project/samples/demo:latest' + image: image ports: { web: { containerPort: 3000 diff --git a/samples/volumes/app.bicep b/samples/volumes/app.bicep index 9654f1a3..36504e27 100644 --- a/samples/volumes/app.bicep +++ b/samples/volumes/app.bicep @@ -2,6 +2,8 @@ import radius as rad param environment string +param image string = 'ghcr.io/radius-project/samples/volumes:latest' + resource app 'Applications.Core/applications@2023-10-01-preview' = { name: 'myapp' properties: { @@ -14,7 +16,7 @@ resource container 'Applications.Core/containers@2023-10-01-preview' = { properties: { application: app.id container: { - image: 'ghcr.io/radius-project/samples/volumes:latest' + image: image volumes: { temp: { kind: 'ephemeral'