icokpy/ok

Create pipeline for deployment

Closed this issue · 8 comments

Create pipeline for deployment

Initial tasks:

  1. Configure Azure Jenkins instance to point to the ICOKPy registry
    1.1 Attempt 1 (failed) - configured at the end of the project web config page, credentials from portal.azure. Appears to be attempting to access the registry via git? See http://localhost:8080/blue/organizations/jenkins/OK/detail/PR-15/6/pipeline
    1.2 Comment - 1.1 is looking at the problem backwards; Jenkins should continue to default to Dockerhub, and only reference the ICOKPy registry when pushing post-master-success. So the hack needed here is working out how to get an in-repo Jenkinsfile to access credentials stored locally in the Jenkins instance.
    1.3 Attempt 2(a) - Try using the method documented at: https://jenkins.io/doc/book/pipeline/docker/#custom-registry ; created a branch ( jenkins/dummy-push-to-custom-repo ) to try pushing a test image to the registry as proof of concept.
    1.4 Hit a snag in terms of writing all the Jenkins config in declarative pipeline - doesn't appear to be a way to push the image from declarative; the supported method is docker.withregistry(...) in scripted.
    1.5 Fix 1.4 by wrapping the post{} section in script {} ; this will at some point become deprecated and need to be updated to declarative. This appears to be working, using:
    https://github.com/icokpy/ok/blob/jenkins/dummy-push-to-custom-registry/Jenkinsfile
    and running through Jenkins with:
    http://ok-jenkins.uksouth.cloudapp.azure.com/blue/organizations/jenkins/OK/detail/jenkins%2Fdummy-push-to-custom-registry/14/pipeline

  2. Pushes should only happen when building master branch.
    2.1. Trying: when { branch 'master' } conditional in the post {} stage - fails but with no useful logs available
    2.2 Trying putting the conditional when{} before the post{} stage - still fails
    2.3 Wrap the scripted docker step in an if{} - works.

  3. Docker tags should be set appropriately / uniquely through the build
    3.1 Environment variables don't get substituted correctly in the Jenkinsfile - fixed by switching from single-quote to double-quote strings
    3.2 Docker tags must be all lower case - fixed by pre-formatting env.BUILD_TAG to lower case
    3.3 NOTE - going to cause problems with special characters (notably, percentage) in tags

PR merged into master - check the registry when build completes to see whether the built image was published.

It dind't; fixing with a general rewrite as per PR #32

To-do list:

  • Create / obtain a service principal --DONE
  • Add service principal to Jenkins --DONE
  • Add az cli deployment comomand to Jenkinsfile -- IN BRANCH jenkins/add-deploy-code, not merged

PR #38 aims to close this issue

Now returning a region error:

ERROR: Deployment failed. Correlation ID: 0d8c01c5-db52-469c-83dc-08e706b1c3f0. {
"error": {
"code": "LocationNotAvailableForResourceType",
"message": "The provided location 'uksouth' is not available for resource type 'Microsoft.ContainerInstance/containerGroups'. List of available regions for the resource type is 'westus,eastus,westeurope,westus2,northeurope,southeastasia'."
}
}

Fix for region in PR #54

Deploying correctly to dev