Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure samples repo #588

Merged
merged 8 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 51 additions & 105 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,142 +17,90 @@ concurrency:
cancel-in-progress: true

env:
VERSION: ${{ github.event.pull_request.number || 'edge' }}
VERSION: ${{ github.event.pull_request.number || 'latest' }}
# Use radiusdev.azurecr.io for PR build. Otherwise, use radius.azurecr.io.
# TODO_LAUNCH: Remove this env var once we opensource the repo - https://github.com/radius-project/samples/issues/439
DOCKER_REGISTRY: ${{ github.event.pull_request.number && 'radiusdev.azurecr.io' || 'radius.azurecr.io' }}
# Use radiusdev.azurecr.io for PR build. Otherwise, use radius.azurecr.io.
CONTAINER_REGISTRY: ${{ github.event.pull_request.number && 'ghcr.io/radius-project/dev' || 'ghcr.io/radius-project/samples' }}
CONTAINER_REGISTRY: ${{ github.event.pull_request.number && 'ghcr.io/radius-project/dev' || 'ghcr.io/radius-project' }}
# Set to true to push images to registry.
PUSH_IMAGE: true

jobs:
# TODO_LAUNCH: Remove this build job once we opensource the repo - https://github.com/radius-project/samples/issues/439
build:
build-acr:
name: Build and push sample images to ACR
if: github.event.action != 'closed'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- directory: samples/demo/
image: samples/demo
- directory: samples/dapr/ui/
image: samples/dapr-frontend
- directory: samples/dapr/nodeapp/
image: samples/dapr-backend
- directory: samples/aws/
image: samples/aws
- directory: samples/aws-sqs/
image: samples/aws-sqs
- directory: samples/volumes/
image: samples/volumes
steps:
- name: Checkout code
uses: actions/checkout@v3.5.2
uses: actions/checkout@v4
- name: Login to container registry
uses: azure/docker-login@v1
with:
login-server: ${{ env.DOCKER_REGISTRY }}
username: '${{ secrets.AZURE_SP_DOCKER_USERNAME }}'
password: '${{ secrets.AZURE_SP_DOCKER_PASSWORD }}'
- name: demo
uses: docker/build-push-action@v4
with:
context: ./demo/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.DOCKER_REGISTRY }}/tutorial/demo:${{ env.VERSION }}
- name: webapp
uses: docker/build-push-action@v4
with:
context: ./demo/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.DOCKER_REGISTRY }}/tutorial/webapp:${{ env.VERSION }}
- name: dapr-backend
uses: docker/build-push-action@v4
with:
context: ./quickstarts/dapr/nodeapp/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.DOCKER_REGISTRY }}/quickstarts/dapr-backend:${{ env.VERSION }}
- name: dapr-frontend
uses: docker/build-push-action@v4
with:
context: ./quickstarts/dapr/ui/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.DOCKER_REGISTRY }}/quickstarts/dapr-frontend:${{ env.VERSION }}
- name: aws-reference-app
uses: docker/build-push-action@v4
with:
context: ./reference-apps/aws/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.DOCKER_REGISTRY }}/reference-apps/aws:${{ env.VERSION }}
- name: environment-variables
uses: docker/build-push-action@v4
with:
context: ./quickstarts/environment-variables/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.DOCKER_REGISTRY }}/quickstarts/envvars:${{ env.VERSION }}
- name: volumes
uses: docker/build-push-action@v4
with:
context: ./quickstarts/volumes/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.DOCKER_REGISTRY }}/quickstarts/volumes:${{ env.VERSION }}
- name: aws-sqs
- name: Build and push ${{ matrix.image }}
uses: docker/build-push-action@v4
with:
context: ./reference-apps/aws-sqs/
context: ./${{ matrix.directory }}
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.DOCKER_REGISTRY }}/reference-apps/aws-sqs-sample:${{ env.VERSION }}
build-container:
tags: ${{ env.DOCKER_REGISTRY }}/${{ matrix.image }}:${{ env.VERSION }}
build-ghcr:
name: Build and push sample images to GHCR
if: github.event.action != 'closed'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- directory: samples/demo/
image: samples/demo
- directory: samples/dapr/ui/
image: samples/dapr-frontend
- directory: samples/dapr/nodeapp/
image: samples/dapr-backend
- directory: samples/aws/
image: samples/aws
- directory: samples/aws-sqs/
image: samples/aws-sqs
- directory: samples/volumes/
image: samples/volumes
steps:
- name: Checkout code
uses: actions/checkout@v3.5.2
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: demo
uses: docker/build-push-action@v4
with:
context: ./demo/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.CONTAINER_REGISTRY }}/tutorial/demo:${{ env.VERSION }}
- name: webapp
uses: docker/build-push-action@v4
with:
context: ./demo/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.CONTAINER_REGISTRY }}/tutorial/webapp:${{ env.VERSION }}
- name: dapr-backend
uses: docker/build-push-action@v4
with:
context: ./quickstarts/dapr/nodeapp/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.CONTAINER_REGISTRY }}/quickstarts/dapr-backend:${{ env.VERSION }}
- name: dapr-frontend
uses: docker/build-push-action@v4
with:
context: ./quickstarts/dapr/ui/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.CONTAINER_REGISTRY }}/quickstarts/dapr-frontend:${{ env.VERSION }}
- name: aws-reference-app
uses: docker/build-push-action@v4
with:
context: ./reference-apps/aws/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.CONTAINER_REGISTRY }}/reference-apps/aws:${{ env.VERSION }}
- name: environment-variables
uses: docker/build-push-action@v4
with:
context: ./quickstarts/environment-variables/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.CONTAINER_REGISTRY }}/quickstarts/envvars:${{ env.VERSION }}
- name: volumes
uses: docker/build-push-action@v4
with:
context: ./quickstarts/volumes/
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.CONTAINER_REGISTRY }}/quickstarts/volumes:${{ env.VERSION }}
- name: aws-sqs
- name: Build and push ${{ matrix.image }}
uses: docker/build-push-action@v4
with:
context: ./reference-apps/aws-sqs/
context: ./${{ matrix.directory }}
push: ${{ env.PUSH_IMAGE }}
tags: ${{ env.CONTAINER_REGISTRY }}/reference-apps/aws-sqs-sample:${{ env.VERSION }}
tags: ${{ env.CONTAINER_REGISTRY }}/${{ matrix.image }}:${{ env.VERSION }}

# TODO_LAUNCH: Remove this job once we opensource the repo because all pkgs will be cleaned up regularly - https://github.com/radius-project/samples/issues/439
cleanup:
Expand All @@ -163,19 +111,17 @@ jobs:
fail-fast: false
matrix:
image: [
tutorial/webapp,
tutorial/demo,
quickstarts/dapr-backend,
quickstarts/dapr-frontend,
quickstarts/envvars,
quickstarts/volumes,
reference-apps/aws,
reference-apps/aws-sqs-sample,
samples/demo,
samples/dapr-frontend,
samples/dapr-backend,
samples/aws,
samples/aws-sqs,
samples/volumes
]
steps:
- name: Login to az cli and ACR
run: |
az login --service-principal --username ${{ secrets.AZURE_SP_DOCKER_USERNAME }} --password ${{ secrets.AZURE_SP_DOCKER_PASSWORD }} --tenant ${{ secrets.AZURE_SP_DOCKER_TENANT }}
az acr login --name ${{ env.DOCKER_REGISTRY }}
- name: Delete PR images
run: az acr repository delete --name ${{ env.DOCKER_REGISTRY }} --image "${{ matrix.image }}:${{ env.VERSION }}" --yes
run: az acr repository delete --name ${{ env.DOCKER_REGISTRY }} --image "${{ matrix.image }}:${{ env.VERSION }}" --yes
39 changes: 16 additions & 23 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ on:
- v*.*
- edge
paths:
- "quickstarts/**"
- "reference-apps/**"
- "demo/**"
- "samples/**"
- ".github/workflows/**"
pull_request:
types: [opened, synchronize, reopened]
Expand All @@ -38,45 +36,40 @@ jobs:
- name: demo
runOnPullRequest: true
app: demo
path: ./demo/app.bicep
path: ./samples/demo/app.bicep
args: --application demo
uiTestFile: tests/demo/demo.app.spec.ts
port: 3000
container: demo
enableDapr: false
- name: dapr
runOnPullRequest: true
app: dapr-quickstart
path: ./quickstarts/dapr/dapr.bicep
app: dapr
path: ./samples/dapr/dapr.bicep
enableDapr: true
- name: environment-variables
runOnPullRequest: true
app: myapp
path: ./quickstarts/environment-variables/app.bicep
enableDapr: false
- name: volumes
runOnPullRequest: true
app: myapp
path: ./quickstarts/volumes/app.bicep
path: ./samples/volumes/app.bicep
enableDapr: false
- name: eshop
runOnPullRequest: true
app: eshop
path: ./reference-apps/eshop/iac/eshop.bicep
path: ./samples/eshop/iac/eshop.bicep
uiTestFile: tests/eshop/container.app.spec.ts
enableDapr: false
- name: eshop-azure
runOnPullRequest: false
app: eshop-azure
path: ./reference-apps/eshop/iac/eshop.bicep
path: ./samples/eshop/iac/eshop.bicep
args: -p platform=azure -p appName=eshop-azure
uiTestFile: tests/eshop/container.app.spec.ts
credential: azure
enableDapr: false
- name: eshop-aws
runOnPullRequest: false
app: eshop-aws-${{ github.run_id }}-${{ github.run_attempt }}
path: ./reference-apps/eshop/iac/eshop.bicep
path: ./samples/eshop/iac/eshop.bicep
args: -p platform=aws -p eksClusterName=eks-samplestest-${{ github.run_id }}-${{ github.run_attempt }}-eshop-aws -p appName=eshop-aws-${{ github.run_id }}-${{ github.run_attempt }}
uiTestFile: tests/eshop/container.app.spec.ts
credential: aws
Expand Down Expand Up @@ -237,7 +230,7 @@ jobs:
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: |
namespace="default-${{ matrix.app }}"
label="radius.dev/application=${{ matrix.app }}"
label="radapp.io/application=${{ matrix.app }}"
kubectl wait --for=condition=Ready pod -l $label -n $namespace --timeout=5m
- name: Run Playwright Test
if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.uiTestFile != ''
Expand All @@ -250,7 +243,7 @@ jobs:
echo "Endpoint: $endpoint"
export ENDPOINT=$endpoint
fi
cd ui-tests/
cd playwright/
npm ci
npx playwright install --with-deps
npx playwright test ${{ matrix.uiTestFile }} --retries 3
Expand All @@ -259,7 +252,7 @@ jobs:
if: always() && ( steps.run-playwright-test.outcome == 'success' || steps.run-playwright-test.outcome == 'failure' )
with:
name: playwright-report-${{ matrix.name }}
path: ui-tests/playwright-report/
path: playwright/playwright-report/
retention-days: 30
if-no-files-found: error
# Handle failures
Expand All @@ -268,23 +261,23 @@ jobs:
if: failure() && steps.run-playwright-test.outcome == 'failure'
run: |
# Create pod-logs directory
mkdir -p ui-tests/pod-logs/${{ matrix.name }}
mkdir -p playwright/pod-logs/${{ matrix.name }}
# Get pod logs and save to file
namespace="default-${{ matrix.app }}"
label="radius.dev/application=${{ matrix.app }}"
pod_names=($(kubectl get pods -l $label -n $namespace -o jsonpath='{.items[*].metadata.name}'))
for pod_name in "${pod_names[@]}"; do
kubectl logs $pod_name -n $namespace > ui-tests/pod-logs/${{ matrix.name }}/${pod_name}.txt
kubectl logs $pod_name -n $namespace > playwright/pod-logs/${{ matrix.name }}/${pod_name}.txt
done
echo "Pod logs saved to ui-tests/pod-logs/${{ matrix.name }}/"
echo "Pod logs saved to playwright/pod-logs/${{ matrix.name }}/"
# Get kubernetes events and save to file
kubectl get events -n $namespace > ui-tests/pod-logs/${{ matrix.name }}/events.txt
kubectl get events -n $namespace > playwright/pod-logs/${{ matrix.name }}/events.txt
- name: Upload Pod logs for failed tests
uses: actions/upload-artifact@v3
if: failure() && steps.get-pod-logs.outcome == 'success'
with:
name: ${{ matrix.name }}-pod-logs
path: ui-tests/pod-logs/${{ matrix.name }}
path: playwright/pod-logs/${{ matrix.name }}
retention-days: 30
if-no-files-found: error
- name: Create GitHub issue on failure
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions ui-tests/package-lock.json → playwright/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui-tests/package.json → playwright/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ui-tests",
"name": "playwright-tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions quickstarts/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions quickstarts/environment-variables/README.md

This file was deleted.

Loading
Loading