Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
feat(release-pipeline): adjust docker image tags, lock image for rele…
Browse files Browse the repository at this point in the history
…ase branch

Merge branch 'feat/release-pipeline'

* feat/release-pipeline:
  pipeline: add versioned tag, lock image in ACR after push
  feat(release): add npm script to get my project version from package.json
  chore: update .dockerignore, updating pipeline should not change image
  chore: ignore azure cli files
  • Loading branch information
julie-ng committed Feb 25, 2020
2 parents 615e434 + 85cb08c commit c4812c5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
node_modules
coverage/
node_modules/
.DS_Store
azure-pipelines.yml
*.azcli
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage/
node_modules/
.DS_Store
*.azcli
35 changes: 30 additions & 5 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
name: $(BuildID)

trigger:
- master
- feat/*
- master
- release

schedules:
- cron: "0 12 * * 0"
Expand All @@ -25,12 +26,14 @@ variables:
- name: app-services-name
value: azure-nodejs-demo

# Pattern: registry.azurecr.io/demos/app-name:12-gitsha
- name: image-name
value: $(registry-host)/$(registry-namespace)/$(app-name)
value: $(registry-namespace)/$(app-name)

- name: image-name-with-registry
value: $(registry-host)/$(image-name) # e.g. registry.azurecr.io/demos/app-name

- name: image-tag
value: $(Build.BuildId)-$(Build.SourceVersion)
value: $(Build.BuildId)-$(Build.SourceVersion) # e.g. 12-gitsha

stages:
- stage: Tests
Expand Down Expand Up @@ -70,7 +73,15 @@ stages:
displayName: Build and Push Image
steps:

- script: docker build --tag $(image-name):$(image-tag) .
# release: set version to package.json version
- script: |
echo '##vso[task.setvariable variable=image-tag]'$(npm run --silent project-version)''
echo 'Project version is $(image-tag)'
echo 'Image tag set to $(image-tag)'
displayName: 'Overwrite image tag if `release` branch'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/release'), ne(variables['Build.Reason'], 'Schedule'))
- script: docker build --tag $(image-name-with-registry):$(image-tag) .
displayName: 'Docker: Build and tag image'

- task: Docker@1
Expand All @@ -81,6 +92,20 @@ stages:
imageName: $(image-name):$(image-tag)
command: push

# release: lock image
- task: AzureCLI@2
displayName: 'Lock release image, preventing delete'
inputs:
azureSubscription: $(registry-service-connection)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
az --version
az acr repository update \
--name $(registry-acr-name) --image $(image-name):$(image-tag) \
--write-enabled false
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/release'), ne(variables['Build.Reason'], 'Schedule'))

# ----------------------------
# Deploy to Azure App Services
# ----------------------------
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"start": "node app/server.js",
"dev": "NODE_ENV=development nodemon -w app app/server.js",
"lint": "eslint .",
"my-version": "node -e \"console.log(require('./package.json').version)\"",
"release": "standard-version",
"test": "jest",
"test:watch": "jest --watch",
Expand Down

0 comments on commit c4812c5

Please sign in to comment.