This project covers on following topics
- CI via Azure Devops
- Resource creation via Terraform
- CD via Azure Devops
This section contains two major units
This section covers compile and build part for the java application which is done via Azure devops
- job: Build
displayName: Compile and build docker image
steps:
- task: Maven@4
inputs:
mavenPomFile: 'pom.xml'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
Once build is successful it creates a target folder where the jar file gets created from the above step , post which docker runs and creates an image using the jar file
- task: Docker@2
inputs:
command: 'build'
Dockerfile: '**/Dockerfile'
arguments: '-t helloworld:v1'
addPipelineData: false
addBaseImageData: false
# Base image
FROM thothbot/alpine-jre8:latest
# Add Target JAR file
COPY target/myproject-0.0.1-SNAPSHOT.jar ./
# Expose ports
EXPOSE 8080:8080
# Modify Users
USER 1001
# Entry point for Application
ENTRYPOINT ["java", "-jar", "./myproject-0.0.1-SNAPSHOT.jar"]
This is a seperate pipeline which is responsible for creation on underlying infrastructure. pipeline
This has two sections
1. Modules Modules
They are re-usable and can be added multiple times into different repos
2. Actual infra TF files Files
This section is using the re-usable modules to create the infrastructure.
This section is included in the same yaml file, these steps are done using azure devops steps only.
- stage: DeployDocker
displayName: Deploy jar file to virtual machine
jobs:
- job: Deployment
displayName: deploy docker
steps:
- task: Bash@3
displayName: Upload docker file to machine
inputs:
targetType: 'inline'
script: 'docker save -o helloworld.tar helloworld:v1'
- task: Bash@3
displayName: Upload file to destination
inputs:
targetType: 'inline'
script: 'ssh ssh [email protected] tar czf - helloworld.tar > /tmp/helloworld.tar;'
- While creating the VM via terraform, I have used the local SSH key instead of creating one via TF, In case if you are testing the module, please create a SSH key with name ~/.ssh/id_rsa.pub
- You need to run Terraform pipeline first so that infra is created first and then some additions are needed in pipeline variables so that the correct VM is picked up.