From 43faf5eb2fcf7952a700af8a3dd63a76e89859af Mon Sep 17 00:00:00 2001 From: Maksim Kopnov <44946644+mvktsk@users.noreply.github.com> Date: Wed, 21 Apr 2021 09:02:05 +0700 Subject: [PATCH] VDS-1275: Storefront automate deployment (#65) * VDS-1275: Storefront automate deployment * VDS-1275: Fix Invoke VC image deployment workflow condition --- .github/workflows/deploy-pr.yml | 28 +++++++++++++----------- .github/workflows/deploy.yml | 20 ++++++++--------- .github/workflows/main.yml | 38 ++++++++++++++++++++------------- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index d0c1b1f1..6f2be0cd 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -1,6 +1,6 @@ # v1.0 -name: Deploy Theme to environments +name: Deploy Storefront to environments on: pull_request: paths-ignore: @@ -17,6 +17,7 @@ jobs: runs-on: ubuntu-latest env: GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} + ARTIFACT_KEY: "docker.pkg.github.com/virtocommerce/vc-storefront/storefront" steps: - name: Gets artifact link @@ -25,29 +26,30 @@ jobs: - name: Create deploy PR in QA if: github.event.action != 'closed' && contains(github.event.pull_request.labels.*.name, 'deploy-qa') && !contains(github.event.pull_request.labels.*.name, 'deploy-demo') - uses: VirtoCommerce/vc-github-actions/create-deploy-pr@master + uses: VirtoCommerce/vc-github-actions/create-deploy-pr@VDS-1275 with: deployRepo: "vc-webstore-deploy" deployBranch: "qa" - artifactKey: "B2B_THEME_URL" + artifactKey: ${{ env.ARTIFACT_KEY}} artifactUrl: "${{ steps.artifactLink.outputs.artifactUrl }}" taskNumber: "${{ steps.artifactLink.outputs.qaTaskNumber }}" + cmPath: "webstore-app/resources/kustomization.yaml" - name: Create deploy PR in Demo if: github.event.action == 'closed' && github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'deploy-demo') - uses: VirtoCommerce/vc-github-actions/create-deploy-pr@master + uses: VirtoCommerce/vc-github-actions/create-deploy-pr@VDS-1275 with: deployRepo: "vc-webstore-deploy" deployBranch: "master" - artifactKey: "B2B_THEME_URL" + artifactKey: ${{ env.ARTIFACT_KEY}} artifactUrl: "${{ steps.artifactLink.outputs.artifactUrl }}" taskNumber: "${{ steps.artifactLink.outputs.demoTaskNumber }}" + cmPath: "webstore-app/resources/kustomization.yaml" - - name: Deploy to Dev - if: github.event.action == 'closed' && github.event.pull_request.merged == true - uses: benc-uk/workflow-dispatch@v1 - with: - workflow: Theme deployment - token: ${{ secrets.REPO_TOKEN }} - inputs: '{ "blobUrl": "${{ steps.artifactLink.outputs.artifactUrl }}", "artifactVersion": "PR-${{ github.event.pull_request.number }}", "key": "B2B_THEME_URL" }' - + # - name: Deploy to dev + # if: github.event.action == 'closed' && github.event.pull_request.merged == true + # uses: benc-uk/workflow-dispatch@v1 + # with: + # workflow: VC image deployment + # token: ${{ secrets.REPO_TOKEN }} + # inputs: '{ "baseImageName": "docker.pkg.github.com/virtocommerce/vc-storefront/storefront", "artifactLink": "${{ steps.artifactLink.outputs.artifactUrl }}" }' diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 56d3d235..6095e02c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,5 @@ -# v0.1 +# v0.2 + name: VC image deployment on: workflow_dispatch: @@ -6,11 +7,8 @@ on: baseImageName: description: 'Base kustomize image name' required: true - imageName: - description: 'Deploying image name' - required: true - artifactVersion: - description: 'Full artifact build number' + artifactLink: + description: 'Full link to artifact docker image' required: true appDescriptionRepo: description: 'ArgoCd repository' @@ -21,7 +19,6 @@ on: required: true default: 'dev' - jobs: cd: runs-on: ubuntu-latest @@ -46,18 +43,19 @@ jobs: - name: Update kustomize shell: pwsh run: | - $REPOSITORY = "docker.pkg.github.com/$('${{ github.repository }}'.ToLower())" cd ${{ github.workspace }} cd ./webstore-app/resources - kustomize edit set image ${{ github.event.inputs.baseImageName }}=$REPOSITORY/${{ github.event.inputs.imageName }}:${{ github.event.inputs.artifactVersion }} + kustomize edit set image ${{ github.event.inputs.baseImageName }}=${{ github.event.inputs.artifactLink }} + + - uses: VirtoCommerce/vc-github-actions/setup-git-credentials-github@master + with: + githubToken: ${{ secrets.REPO_TOKEN }} - name: Commit kustomize change shell: pwsh run: | if(git status --porcelain |Where {$_ -notmatch '^\?\?'}) # uncommitted changes exist { - git config --global user.name 'vc-ci' - git config user.email --global 'ci@virtocommerce.com' git commit -am 'Automated update ${{ github.repository }} to ${{ github.event.inputs.artifactVersion }}' git push } diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 23fd3051..d95c7704 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -# v1.1.2.vc-demo-storefront +# v1.1.4.vc-demo-storefront name: Storefront CI # Controls when the action will run. Triggers the workflow on push or pull request @@ -30,6 +30,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} NUGET_KEY: ${{ secrets.NUGET_KEY }} BLOB_SAS: ${{ secrets.BLOB_TOKEN }} + IMAGE_NAME: "demo-storefront" PUBLISH_TO_DOCKER: "false" UPDATE_LATEST_TAG: "true" VERSION_SUFFIX: "" @@ -37,10 +38,11 @@ jobs: steps: - name: Set variables - if: ${{ github.event_name == 'workflow_dispatch' }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' }} run: | - echo "PUBLISH_TO_DOCKER=false" >> $GITHUB_ENV echo "UPDATE_LATEST_TAG=false" >> $GITHUB_ENV + # echo "PUBLISH_TO_DOCKER=false" >> $GITHUB_ENV + - name: Set up JDK 11 for dotnet-sonarscanner #Sonar stop accepting Java versions less than 11 uses: actions/setup-java@v1 @@ -106,20 +108,20 @@ jobs: run: vc-build Compress -skip Clean+Restore+Compile+Test - name: Build Docker Image - if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master') }} + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master') }} id: dockerBuild uses: VirtoCommerce/vc-github-actions/build-docker-image@master with: tag: ${{ steps.image.outputs.taggedVersion }} - imageName: "demo-storefront" + imageName: ${{ env.IMAGE_NAME }} dockerFiles: "https://raw.githubusercontent.com/VirtoCommerce/vc-docker/master/linux/storefront/Dockerfile" - - name: Publish to Blob - if: ${{ github.ref == 'refs/heads/dev' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master') }} - id: blobRelease - uses: VirtoCommerce/vc-github-actions/publish-blob-release@master - with: - blobSAS: ${{ secrets.BLOB_TOKEN }} + # - name: Publish to Blob + # if: ${{ github.ref == 'refs/heads/dev' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master') }} + # id: blobRelease + # uses: VirtoCommerce/vc-github-actions/publish-blob-release@master + # with: + # blobSAS: ${{ secrets.BLOB_TOKEN }} - name: Publish Github Release if: ${{ github.ref == 'refs/heads/master' }} @@ -128,7 +130,7 @@ jobs: uses: VirtoCommerce/vc-github-actions/publish-github-release@master - name: Docker Login - if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master') }} + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master') }} uses: azure/docker-login@v1 with: login-server: docker.pkg.github.com @@ -136,7 +138,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Publish Docker Image - if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master') }} + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master') }} uses: VirtoCommerce/vc-github-actions/publish-docker-image@master with: image: ${{ steps.dockerBuild.outputs.imageName }} @@ -146,10 +148,16 @@ jobs: docker_hub: ${{ env.PUBLISH_TO_DOCKER }} update_latest: ${{ env.UPDATE_LATEST_TAG }} + - name: Add link to PR + if: ${{ github.event_name == 'pull_request' }} + uses: VirtoCommerce/vc-github-actions/publish-artifact-link@master + with: + artifactUrl: "docker.pkg.github.com/${{ github.repository }}/${{ env.IMAGE_NAME }}:${{ steps.image.outputs.taggedVersion }}" + - name: Invoke VC image deployment workflow - if: ${{(github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master')}} + if: ${{ github.ref == 'refs/heads/dev' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master')}} uses: benc-uk/workflow-dispatch@v1 with: workflow: VC image deployment token: ${{ secrets.REPO_TOKEN }} - inputs: '{ "baseImageName": "docker.pkg.github.com/virtocommerce/vc-storefront/storefront", "imageName": "demo-storefront", "artifactVersion": "${{ steps.image.outputs.taggedVersion }}"}' + inputs: '{ "baseImageName": "docker.pkg.github.com/virtocommerce/vc-storefront/storefront", "artifactLink": ""docker.pkg.github.com/${{ github.repository }}/${{ env.IMAGE_NAME }}:${{ steps.image.outputs.taggedVersion }}"}" }'