Skip to content

Commit

Permalink
docker scripts and Jenkinsfile
Browse files Browse the repository at this point in the history
  • Loading branch information
jareddlc committed Apr 10, 2017
1 parent 3eb3ae7 commit ebb3ff3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
13 changes: 13 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!groovy

node {
stage("Checkout") {
checkout scm
}
stage("Build") {
sh "docker-build.sh"
}
stage("Deploy") {
sh "docker-service.sh"
}
}
17 changes: 0 additions & 17 deletions docker-build.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#!/bin/bash

docker kill jareddlc_com &> /dev/null
KILL=$?
if [ $KILL -ne 0 ]; then
echo "Docker kill failed"
#exit $KILL
fi

docker rm jareddlc_com &> /dev/null
RM=$?
if [ $RM -ne 0 ]; then
echo "Docker remove failed"
#exit $RM
fi

docker build -t jareddlc.com .

echo "Container: docker run -d --name jareddlc_com -p 80 jareddlc.com"
echo "Service: docker service create --replicas 1 --name jareddlc_com -p 80 jareddlc.com"
3 changes: 3 additions & 0 deletions docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker run -d --name jareddlc_com -p 80 jareddlc.com
21 changes: 21 additions & 0 deletions docker-service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Check to see if service is running
output="$(docker service ls 2>/dev/null | grep jareddlc_com)"
if [ -z "$output" ]; then
echo "Docker service is not running. Creating docker service..."
docker service create --replicas 1 --name jareddlc_com -p 80 jareddlc.com
exit 0
fi
echo "Docker service is running."

# Check container id
containerId=$(docker ps | grep jareddlc_com | awk '{print $1}')
if [ -z "$containerId" ]; then
echo "Docker container id not found"
exit 1
fi

# Kill the container to force docker service to create a new container
echo "killing container id: $containerId"
docker kill "$containerId"

0 comments on commit ebb3ff3

Please sign in to comment.