diff --git a/.github/workflows/ci-pr.yaml b/.github/workflows/ci-pr.yaml new file mode 100644 index 0000000..e15f346 --- /dev/null +++ b/.github/workflows/ci-pr.yaml @@ -0,0 +1,56 @@ +name: CI for Pull Requests + +on: + pull_request: + branches: + - main # Run the workflow for PRs targeting the "main" branch + +jobs: + test: + runs-on: ubuntu-latest + + steps: + # Step 1: Check out the code from the PR branch + - name: Checkout code + uses: actions/checkout@v2 + + # Step 2: Set up Node.js + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20.x' + + # Step 3: Install MBT and dependencies + - name: Install MBT and dependencies + run: | + npm install -g mbt + cd code + npm install --production + + # Step 4: Install CF Cli + - name: Install CF Cli + run: | + wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add - + echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list + + # Step 5: Install Multiapps Plugin + - name: Install Multiapps Plugin + run: | + cf add-plugin-repo CF-Community https://plugins.cloudfoundry.org + cf install-plugin multiapps -f + + # Step 6: Login to CF + - name: Log in to Cloud Foundry + run: | + cf login -u ${{ secrets.CF_USERNAME }} -p ${{ secrets.CF_PASSWORD }} -o ${{ secrets.CF_ORG }} -s ${{ secrets.CF_SPACE }} -a ${{ secrets.CF_API }} + + # Step 7: Build the project + - name: Build MTA Archive + run: | + cd deploy/cf + mbt build + + # Step 8: Verify MTA Archive built successfully + - name: Deploy to CF + run: | + cf deploy ./deploy/cf/mta_archives/susaas_0.0.1.mtar diff --git a/code/broker/start.js b/code/broker/start.js index 9d0fd8f..92869a7 100644 --- a/code/broker/start.js +++ b/code/broker/start.js @@ -3,12 +3,34 @@ import Broker from '@sap/sbf'; +// If this is a CI CD deployment we get broker credentials from env and hardcode the catalog. +if (process.env.cicd) { + const catalog = `{ + "services": [ + { + "name": "susaas-api", + "description": "Sustainable SaaS API", + "bindable": true, + "plans": [ + { + "name": "default", + "description": "Standard Plan", + "id": "57030d69-3e2d-4dd9-a138-21f16b542dff" + } + ], + "id": "6dec18a5-4742-450f-8840-ef9df0331b20" + } + ] + }` + let brokerConfig = { brokerCredentials: { [process.env["BROKER_USER"]]: process.env["BROKER_PASSWORD"] }, catalog: JSON.parse(catalog) } + new Broker(brokerConfig).start() +} // If VCAP_APPLICATION is defined, we are in a Cloud Foundry scenario // For local testing, the USER and PASSWORD are always injected via environment variables -if(process.env.VCAP_APPLICATION && process.env.NODE_ENV === "production"){ +else if (process.env.VCAP_APPLICATION && process.env.NODE_ENV === "production" && process.env.cicd !== true) { new Broker().start(); -}else{ +} else { // In production Kyma scenarios and local testing, BROKER_USER and BROKER_PASSWORD are passed in env variables - let brokerConfig = { brokerCredentials : { [process.env["BROKER_USER"]] : process.env["BROKER_PASSWORD"] }} + let brokerConfig = { brokerCredentials: { [process.env["BROKER_USER"]]: process.env["BROKER_PASSWORD"] } } new Broker(brokerConfig).start() } \ No newline at end of file