0
votes

Azure App service slot deployment using circleci config.yml

Need to add a step to deploy to production slot or staging slot then modify the config to swap the deployment

Description: When i run this config file then it deploys to production slot of azure app service by default , but i want to deploy to stage slot first and then do a swap .

below file is working fine but need some configuration changes so that i should be able to deploy to stage slot and then swap the slot to the production slot .

Using Circleci config.yml , below is my config.yml

version: 2.1

jobs:
  build:
    docker:
        - image: circleci/node:10.16.3
    steps:

      ## Fetch all release tags
      - checkout
      - run:
          name: Install Node.js dependencies with Npm
          command: npm install
      - run:
          name: Test
          command: CI=true npm run coverage



  dev-deploy:
    machine: true
    steps:
      - checkout
      - run:

          name: create / update infrastructure
          command: |

            docker login -u $REGISTRY_UN -p $REGISTRY_PW $REGISTRY_SERVER

            docker run --rm -it -e TF_VAR_repo_branch=$CIRCLE_BRANCH -e vaultkey=$VAULT_KEY -v `pwd`:/dp/config  dockerimage/dpdeployer:beta-1.0  .dp.yaml



workflows:
  version: 2
  build_and_test_publish:
    jobs:
       - build
      #  - hold: # <<< A job that will require manual approval in the CircleCI web application.
      #      type: approval # <<< This key-value pair will set your workflow to a status of "On Hold"
      #      requires: # We only run the "hold" job when test2 has succeeded
      #       - build

       - dev-deploy:
          requires:

            - build

          filters:
            branches: 
              only : feature/appservice

2

2 Answers

1
votes

Hmmm, this may be a good link to review: Deploy to Azure from CircleCI

But, I think it comes down to how you want to deploy your code to Azure App Service. There are a lot of different ways to do so. Checking your config, you are using Docker already. This link, https://docs.microsoft.com/en-us/azure/app-service/containers/tutorial-custom-docker-image , talks about the steps for deploying your container as an Azure App Service. The gist of it seems to be you need to configure your WebApp to pull from a docker registry per Azure app slot .

Then after a successful build, have circleci push/tag the docker image to that registry. Then Azure App Service will start up the new version of the app.

For jumping between Azure App service slots, you could have your circleci config push to different docker registry image tags. This would require setting up each Azure App Service slot with a slightly different config. For example ...

# Dev
  az webapp config container set --name <app-name> --resource-group <rg> --docker-custom-image-name <registry-name>/mydockerimage:$VERSION_FOR_DEV ... 
# Staging
  az webapp config container set --name <app-name> --resource-group <rg> --docker-custom-image-name <registry-name>/mydockerimage:$VERSION_FOR_STAGE ...

In your circleCI config, when you setup your pipeline between dev , stage and production jobs. Dev and Stage jobs would either do docker pushes or tagging for you. And the Production job does the swap for you for the final step. Something like this...

prod-deploy:
   steps:
     - run:
        name: swap staging and product slots
        command: az webapp deployment slot swap  -g MyResourceGroup -n MyUniqueApp --slot staging --target-slot production

Also see: https://docs.microsoft.com/en-us/cli/azure/webapp/deployment/slot?view=azure-cli-latest#az-webapp-deployment-slot-swap

Hopefully this helps..and I did not misunderstand your question. 🤞

0
votes

Yes, it worked!!! Thanks

Although as per our current deployment structure , We are using a deploy script and handling swapping from there and then deploying an application through CircleCI.