Skip to content

Commit

Permalink
docker ansible jenkins
Browse files Browse the repository at this point in the history
  • Loading branch information
yoowonsuk committed Nov 9, 2022
1 parent 3efb54b commit 2a50203
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Jenkins-docker-ansible
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
pipeline {
agent none

stages {
stage('Checkout') {
agent any
steps {
git branch: 'main', url: 'https://github.com/yoowonsuk/source-maven-java-spring-hello-webapp'
}
}
stage('Build') {
agent {
docker { image 'maven:3-openjdk-8' }
}
steps {
sh 'mvn clean package -DskipTests=true'
}
}
stage('Test') {
agent {
docker { image 'maven:3-openjdk-8' }
}
steps {
sh 'mvn test'
}
}
stage('Build Docker Image') {
agent any
steps {
sh 'docker image build -t hellotomcat1 .'
}
}
stage('Tag Docker Image') {
agent any
steps {
sh 'docker image tag hellotomcat1 rkddkwlrhdiddl/hellotomcat1:v1'
}
}
stage('Publish Docker Image') {
agent any
steps {
withDockerRegistry(credentialsId: 'docker-hub-token', url: 'https://index.docker.io/v1/') {
sh 'docker image push rkddkwlrhdiddl/hellotomcat1:v1'
}
}
}
stage('Run Docker Container') {
agent {
docker {
image 'rkddkwlrhdiddl/jenkins-ansible'
args '-u 0:0 -e DOCKER_HOST=tcp://172.31.30.114:2375'
}
}
steps {
ansiblePlaybook(playbook: 'docker-container-deploy.yaml')
}
}
}
}
11 changes: 11 additions & 0 deletions docker-container-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- hosts: localhost
connection: local

tasks:
- name: Create & Start Container
docker_container:
name: myweb
image: "rkddkwlrhdiddl/hellotomcat1:{{lookup('env', 'BUILD_NUMBER')}}"
state: started
ports:
- "80:8080"

0 comments on commit 2a50203

Please sign in to comment.