Skip to content

Commit

Permalink
[Feature][Add] Added Azure DevOps CI/CD pipeline (#5)
Browse files Browse the repository at this point in the history
* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>

* Added Azure CI

Signed-off-by: iamabhishek-dubey <abhishekbhardwaj510@gmail.com>
  • Loading branch information
iamabhishek-dubey committed May 15, 2021
1 parent e1ae0ae commit de33702
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 3 deletions.
179 changes: 177 additions & 2 deletions .azure-pipeline/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,187 @@ pr:
include:
- master

variables:
- group: RuntimeVariables

stages:
- stage: precheck
jobs:
- job: spellcheck
- job: govet
dependsOn: []
pool:
vmImage: "ubuntu-18.04"
steps:
- script: scripts/spellcheck.sh
- task: GoTool@0
displayName: "Installing Golang"
inputs:
version: '1.16'
- task: Go@0
displayName: "Executing go vet"
inputs:
command: 'custom'
customCommand: 'vet'

- stage: code_quality
dependsOn: ["precheck"]
jobs:
- job: golang_ci_lint
dependsOn: []
pool:
vmImage: "ubuntu-18.04"
steps:
- task: GoTool@0
displayName: "Installing Golang"
inputs:
version: '1.16'
- script: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.40.0
./bin/golangci-lint run --timeout 5m0s ./...
displayName: "Executing golang-ci lint"
- stage: dockerfile_lint
dependsOn: ["precheck"]
jobs:
- job: dockerfile_lint
dependsOn: []
pool:
vmImage: "ubuntu-18.04"
steps:
- script: scripts/dockerfile-linter.sh
displayName: "Executing dockerlinter"

- stage: build
dependsOn: ["code_quality"]
jobs:
- job: linux_amd64
dependsOn: []
pool:
vmImage: "ubuntu-18.04"
steps:
- task: GoTool@0
displayName: "Installing Golang"
inputs:
version: '1.16'
- task: Go@0
displayName: "Executing go build"
inputs:
command: 'build'
arguments: '-o $(Agent.BuildDirectory)/k8s-secret-injector'
- task: ArchiveFiles@2
displayName: 'Archiving go binary'
inputs:
rootFolderOrFile: '$(Agent.BuildDirectory)/k8s-secret-injector'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/compiled/k8s-secret-injector-linux-amd64.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/compiled'
ArtifactName: 'drop'
publishLocation: 'Container'

- stage: build_image
dependsOn: ["dockerfile_lint"]
jobs:
- job: linux_amd64
dependsOn: []
steps:
- task: Docker@2
displayName: "Building docker image"
inputs:
command: 'build'
Dockerfile: '**/Dockerfile'
tags: '$(Build.BuildId)'

- stage: release_binaries
dependsOn: ["build", "build_image"]
jobs:
- job: goreleaser
dependsOn: []
pool:
vmImage: "ubuntu-18.04"
steps:
- script: scripts/goreleaser.sh
displayName: "Releasing go binaries"
env:
GITHUB_TOKEN: $(GithubToken)
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))

- stage: release_quay
dependsOn: ["build", "build_image"]
jobs:
- job: quay
dependsOn: []
pool:
vmImage: "ubuntu-18.04"
steps:
- task: Docker@2
displayName: "Publish quay image"
inputs:
containerRegistry: 'QuayServiceConnection'
repository: 'quay.io/opstree/k8s-secret-injector'
command: 'buildAndPush'
Dockerfile: '**/Dockerfile'
tags: |
latest
$(Build.SourceBranchName)
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))

- stage: release_github_image
dependsOn: ["build", "build_image"]
jobs:
- job: github
dependsOn: []
pool:
vmImage: "ubuntu-18.04"
steps:
- task: Docker@2
displayName: "Publish github image"
inputs:
containerRegistry: 'GithubServiceConnection'
repository: 'docker.pkg.github.com/ot-container-kit/k8s-secret-injector/k8s-secret-injector'
command: 'buildAndPush'
Dockerfile: '**/Dockerfile'
tags: |
latest
$(Build.SourceBranchName)
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))

- stage: verify
dependsOn: ["release_binaries", "release_quay", "release_github_image"]
jobs:
- job: verfiy
dependsOn: []
pool:
vmImage: "ubuntu-18.04"
steps:
- task: DownloadBuildArtifacts@0
displayName: "Downloading the artifact"
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'
- task: ExtractFiles@1
displayName: "Extracting files"
inputs:
archiveFilePatterns: '$(System.ArtifactsDirectory)/drop/k8s-secret-injector-linux-amd64.zip'
destinationFolder: '$(Agent.BuildDirectory)'
cleanDestinationFolder: false
overwriteExistingFiles: true
- script: |
$(Agent.BuildDirectory)/k8s-secret-injector --help
displayName: "Executing k8s-secret-injector"
- stage: docs
dependsOn: ["release_binaries", "release_quay", "release_github_image"]
jobs:
- job: verfiy
dependsOn: []
pool:
vmImage: "ubuntu-18.04"
steps:
- script: |
echo "No documentation is for this project!!"
displayName: "Building documentation"
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0
v4.0
17 changes: 17 additions & 0 deletions scripts/dockerfile-linter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

download_hadolint() {
wget https://github.com/hadolint/hadolint/releases/download/v2.4.0/hadolint-Linux-x86_64
chmod +x hadolint-Linux-x86_64
}

execute_hadolint() {
./hadolint-Linux-x86_64 Dockerfile --ignore DL3007 --ignore DL3018
}

main() {
download_hadolint
execute_hadolint
}

main
25 changes: 25 additions & 0 deletions scripts/goreleaser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

install_goreleaser() {
curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh
}

release() {
install_goreleaser
goreleaser release --rm-dist
}

compare_version() {
version=$(cat VERSION)
if ! git tag -l | grep "${version}"
then
echo "git tag ${version}"
git tag "${version}"
release
else
git tag -l
echo "Latest version is already updated"
fi
}

compare_version

0 comments on commit de33702

Please sign in to comment.