diff --git a/azure-pipelines-1.yml b/azure-pipelines-1.yml new file mode 100644 index 000000000..f461d5325 --- /dev/null +++ b/azure-pipelines-1.yml @@ -0,0 +1,45 @@ +# Docker +# Build a Docker image +# https://docs.microsoft.com/azure/devops/pipelines/languages/docker + +trigger: +- master + +resources: +- repo: self + + + +variables: + tag: '$(Build.BuildId)' + + +stages: +- stage: Build + displayName: Build image + jobs: + - job: Build + displayName: Build + pool: + vmImage: ubuntu-latest + steps: + + - task: Docker@2 + displayName: Build an image + inputs: + command: build + dockerfile: '$(Build.SourcesDirectory)/Dockerfile' + tags: | + '$(Build.SourcesDirectory):$tag' + + + + + - task: Docker@2 + displayName: Push the Built Image + inputs: + containerRegistry: 'connection to DevHarbor Container Registry' + repository: '$(Build.Repository.Name)/$(Build.Repository.Name)' + command: 'push' + tags: | + $(Build.BuildNumber)) diff --git a/azure-pipelines-2.yml b/azure-pipelines-2.yml new file mode 100644 index 000000000..73bad0eea --- /dev/null +++ b/azure-pipelines-2.yml @@ -0,0 +1,23 @@ +stages: +- stage: ExampleStage + jobs: + - job: Job1 + displayName: 'Job 1' + pool: + vmImage: 'windows-latest' + + steps: + - script: | + echo "##vso[task.setvariable variable=variableFromJob1]$variableFromJob1" + displayName: 'Set Output Variable' + + - job: Job2 + displayName: 'Job 2' + dependsOn: Job1 + pool: + vmImage: 'windows-latest' + + steps: + - script: | + echo "Variable from Job 1: $(variableFromJob1)" + displayName: 'Use Output Variable' \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..539f780bf --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,120 @@ +name: Build pipeline + +trigger: +- main + + +jobs: +- job: CI + displayName: "CI Pipeline" + pool: + vmImage: 'ubuntu-latest' + + + variables: + HELM_EXPERIMENTAL_OCI: 1 + registryName: '40.76.167.146' + BuildId: '$(Build.BuildId)' + tag: '$(Build.BuildId)' + reponame: '$(Build.Repository.Name)' + + + steps: + + - task: Bash@3 + name: 'Docker_login_Harbor' + inputs: + targetType: 'inline' + script: | + # Write your commands here + cat /etc/docker/daemon.json + echo '{ "exec-opts": ["native.cgroupdriver=cgroupfs"], "cgroup-parent": "/actions_job", "insecure-registries": ["0.0.0.0/0"] }' | sudo tee /etc/docker/daemon.json + echo "restart docker..." + cat /etc/docker/daemon.json + sudo systemctl daemon-reload + sudo systemctl restart docker + docker login http://40.76.167.146:80 -u admin -p $(harbor-passwd) + + - script: | + full_name=$(reponame) + IFS='/' read -ra parts <<< "$full_name" + second_half=${parts[1]} + echo "##vso[task.setvariable variable=second_half]$second_half" + displayName: 'Set Second Half as Environment Variable' + + - task: Bash@3 + name: 'Docker_build' + inputs: + targetType: 'inline' + script: | + # Write your commands here + echo "docker push" $(registryName)/nqcc/$(second_half):$(BuildId) + docker build -t $(registryName)/nqcc/$(second_half):$(BuildId) . + docker images + echo 'Build Success!' + #workingDirectory: '$(Build.SourcesDirectory)/AppA.WebApi' + displayName: 'Build docker Image in the Worker' + + - task: Bash@3 + name: 'Docker_push' + inputs: + targetType: 'inline' + script: | + docker login http://40.76.167.146:80 -u admin -p $(harbor-passwd) + # Write your commands here + cat /etc/docker/daemon.json + cat ~/.docker/daemon.json + # echo "Logging again to mitigate issue" + #docker logout http://40.76.167.146:80 + # docker login http://40.76.167.146:80 -u admin -p $(harbor-passwd) + # echo "docker push" $(registryName)/nqcc/$(second_half):$(BuildId) + + docker push $(registryName)/nqcc/$(second_half):$(BuildId) + # docker images + # echo 'Build Success!' + displayName: 'Update Docker Image in the remote Registry' + + +- job: CD + displayName: "CD Pipeline" + pool: + vmImage: 'ubuntu-latest' + + + steps: + + - task: Bash@3 + displayName: 'Update Helm Chart ' + inputs: + targetType: 'inline' + script: | + apt-get update -y && apt-get install openssh-client git -y + mkdir -p ˜/.ssh + echo $(ssh-private-key) + echo "$(ssh-private-key)" > /root/.ssh/id_rsa + chmod 600 /root/.ssh/id_rsa + ssh-keyscan -H gitlab.com >> ~/.ssh/known_hosts + chmod 644 ~/.ssh/known_hosts + eval $(ssh-agent -s) + echo "$ssh-private-key" | tr -d '\r' | ssh-add - + git config --global user.email "rodrigo.rras@gmail.com" + git config --global user.name "rodrigo.rras" + git clone git@gitlab.com:container-solutions/nqcc-helmcharts.git + cd nqcc-app + ls -latr + - task: Bash@3 + displayName: 'Update Helm Chart ' + inputs: + targetType: 'inline' + script: | + # Update Image TAG + - sed -i "s/login_demo:.*/login_demo:$(tag)/g" values.yaml + - git add values.yaml + - git commit -am "Update Image" + - git push + + + + + + \ No newline at end of file