From a3b7491bc4431823ef921fd5a0877927af0db2ab Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Tue, 30 Apr 2024 15:26:14 -0500 Subject: [PATCH] Deploy to azure --- .github/workflows/deploy.yml | 63 ++++++++++++++++++++++++++++++++++ Jenkinsfile | 66 ------------------------------------ manifest.yml | 33 ------------------ 3 files changed, 63 insertions(+), 99 deletions(-) create mode 100644 .github/workflows/deploy.yml delete mode 100644 Jenkinsfile delete mode 100644 manifest.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..9225f5c --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,63 @@ +name: Deploy +on: + workflow_dispatch: + push: + branches: + - main +env: + SPRING_DATASOURCE_URL: ${{ secrets.SPRING_DATASOURCE_URL }} + SPRING_DATASOURCE_USERNAME: ${{ secrets.SPRING_DATASOURCE_USERNAME }} + SPRING_DATASOURCE_PASSWORD: ${{ secrets.SPRING_DATASOURCE_PASSWORD }} + SECURITY_OAUTH2_MAIN_CLIENTID: ${{ secrets.SECURITY_OAUTH2_MAIN_CLIENTID }} + SECURITY_OAUTH2_MAIN_CLIENTSECRET: ${{ secrets.SECURITY_OAUTH2_MAIN_CLIENTSECRET }} + SECURITY_OAUTH2_PIVOTALCLA_TOKENSECRET: ${{ secrets.SECURITY_OAUTH2_PIVOTALCLA_TOKENSECRET }} + AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS_SPRING_IO }} + AZURE_SERVICE_NAME: spring-io + AZURE_RESOURCE_GROUP: spring-io + AZURE_PROJECT_NAME: cla-pivotal-io + +jobs: + build: + runs-on: ubuntu-latest + steps: + # https://github.com/actions/checkout/tags + - name: Checkout + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # 4.1.4 + # https://github.com/actions/setup-java/tags + - name: Set up JDK 17 + uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # 4.2.1 + with: + java-version: '17' + distribution: 'adopt' + # https://github.com/gradle/actions/tags + - name: Validate Gradle wrapper + uses: gradle/actions/wrapper-validation@db19848a5fa7950289d3668fb053140cf3028d43 # 3.3.2 + - name: Build with Gradle + uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # 3.3.2 + with: + arguments: build + # https://github.com/Azure/login/tags + - name: Set up Azure + uses: azure/login@6b2456866fc08b011acb422a92a4aa20e2c4de32 # 2.1.0 + with: + creds: ${{ env.AZURE_CREDENTIALS }} + - name: Set up Azure Spring Extension + run: az extension add --name spring + - name: Create app + run: | + az spring app create \ + --name "$AZURE_PROJECT_NAME" \ + --resource-group "$AZURE_RESOURCE_GROUP" \ + --instance-count 2 \ + --assign-endpoint true \ + --service "$AZURE_SERVICE_NAME" + continue-on-error: true + - name: Deploy + run: | + az spring app deploy \ + --name "$AZURE_PROJECT_NAME" \ + --resource-group "$AZURE_RESOURCE_GROUP" \ + --build-env BP_JVM_VERSION=17 \ + --service "$AZURE_SERVICE_NAME" \ + --env "SPRING_DATASOURCE_URL=${SPRING_DATASOURCE_URL}" "SPRING_DATASOURCE_USERNAME=${SPRING_DATASOURCE_USERNAME}" "SPRING_DATASOURCE_PASSWORD=${SPRING_DATASOURCE_PASSWORD}" "SECURITY_OAUTH2_MAIN_CLIENTID=${SECURITY_OAUTH2_MAIN_CLIENTID}" "SECURITY_OAUTH2_MAIN_CLIENTSECRET=${SECURITY_OAUTH2_MAIN_CLIENTSECRET}" "SECURITY_OAUTH2_PIVOTALCLA_TOKENSECRET=${SECURITY_OAUTH2_PIVOTALCLA_TOKENSECRET}"\ + --artifact-path ./build/libs/pivotal-cla-0.0.1-SNAPSHOT.jar \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 9473b28..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,66 +0,0 @@ -def projectProperties = [ - [$class: 'BuildDiscarderProperty', - strategy: [$class: 'LogRotator', numToKeepStr: '5']] -] -properties(projectProperties) - -def SUCCESS = hudson.model.Result.SUCCESS.toString() -currentBuild.result = SUCCESS - -try { - build: { - stage('Build') { - node { - checkout scm - sh "./ci/scripts/start-services.sh" - try { - withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) { - sh "./gradlew clean assemble check --no-daemon --stacktrace" - - sh "./ci/scripts/install-cf.sh" - withCredentials([usernamePassword(credentialsId: 'onecloud-svc_spring_builds', passwordVariable: 'CF_PASSWORD', usernameVariable: 'CF_USERNAME')]) { - sh "./cf login -a api.sc2-04-pcf1-system.oc.vmware.com -o pivotal-cla -s prod -u '$CF_USERNAME' -p '$CF_PASSWORD'" - } - withCredentials([string(credentialsId: 'pivotal-cla-personal_access_token', variable: 'TOKEN_SECRET')]) { - withCredentials([usernamePassword(credentialsId: 'pivotal-cla-client_id', passwordVariable: 'CLIENT_SECRET', usernameVariable: 'CLIENT_ID')]) { - sh "./ci/scripts/cf-push.sh pivotal-cla $CLIENT_ID $CLIENT_SECRET $TOKEN_SECRET ${currentBuild.number}" - } - } - sh "./cf logout" - } - } catch(Exception e) { - currentBuild.result = 'FAILED: check' - throw e - } finally { - junit '**/build/test-results/*/*.xml' - } - } - } - } -} catch(Exception e) { - currentBuild.result = 'FAILED: deploys' - throw e -} finally { - def buildStatus = currentBuild.result - def buildNotSuccess = !SUCCESS.equals(buildStatus) - def lastBuildNotSuccess = !SUCCESS.equals(currentBuild.previousBuild?.result) - - if(buildNotSuccess || lastBuildNotSuccess) { - - stage('Notifiy') { - node { - final def RECIPIENTS = [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']] - - def subject = "${buildStatus}: Build ${env.JOB_NAME} ${env.BUILD_NUMBER} status is now ${buildStatus}" - def details = """The build status changed to ${buildStatus}. For details see ${env.BUILD_URL}""" - - emailext ( - subject: subject, - body: details, - recipientProviders: RECIPIENTS, - to: "rwinch@pivotal.io" - ) - } - } - } -} diff --git a/manifest.yml b/manifest.yml deleted file mode 100644 index 5ce6304..0000000 --- a/manifest.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- -applications: -- name: pivotal-cla-staging - memory: 1G - instances: 1 - timeout: 180 - services: - - pivotal-cla-mysql-staging - - pivotal-cla-redis-production - env: - SPRING_PROFILES_ACTIVE: cloudfoundry -- name: pivotal-cla-production - memory: 1G - instances: 2 - timeout: 180 - services: - - pivotal-cla-mysql-production - - pivotal-cla-redis-production - env: - SPRING_PROFILES_ACTIVE: cloudfoundry - routes: - - route: cla.pivotal.io -- name: pivotal-cla - memory: 1G - instances: 2 - timeout: 180 - services: - - pivotal-cla-mysql-production - - pivotal-cla-redis-production - env: - SPRING_PROFILES_ACTIVE: cloudfoundry - routes: - - route: cla.pivotal.io