Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
VDS-1275: Storefront automate deployment (#65)
Browse files Browse the repository at this point in the history
* VDS-1275: Storefront automate deployment

* VDS-1275: Fix Invoke VC image deployment workflow condition
  • Loading branch information
mvktsk committed Apr 21, 2021
1 parent 3ce251f commit 43faf5e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
28 changes: 15 additions & 13 deletions .github/workflows/deploy-pr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# v1.0

name: Deploy Theme to environments
name: Deploy Storefront to environments
on:
pull_request:
paths-ignore:
Expand All @@ -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
Expand All @@ -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 }}" }'
20 changes: 9 additions & 11 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# v0.1
# v0.2

name: VC image deployment
on:
workflow_dispatch:
inputs:
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'
Expand All @@ -21,7 +19,6 @@ on:
required: true
default: 'dev'


jobs:
cd:
runs-on: ubuntu-latest
Expand All @@ -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
}
Expand Down
38 changes: 23 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,17 +30,19 @@ 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: ""

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
Expand Down Expand Up @@ -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' }}
Expand All @@ -128,15 +130,15 @@ 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
username: $GITHUB_ACTOR
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 }}
Expand All @@ -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 }}"}" }'

0 comments on commit 43faf5e

Please sign in to comment.