Skip to content

Development #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 61 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
agentName = "server-slave"

pipeline {
agent any
agent none
environment {
//be sure to replace "willbla" with your own Docker Hub username
DOCKER_IMAGE_NAME = "willbla/train-schedule"
MYIMAGE = "$DOCKER_IMAGE_NAME:$BUILD_NUMBER"
DOCKER_IMAGE_NAME = "shdh/train-schedule"
VERSION = "2"

}
stages {
stage('Build') {
agent { label agentName }
steps {
echo 'Running build automation'
sh './gradlew build --no-daemon'
Expand All @@ -14,8 +20,9 @@ pipeline {
}
stage('Build Docker Image') {
when {
branch 'master'
branch 'development'
}
agent { label agentName }
steps {
script {
app = docker.build(DOCKER_IMAGE_NAME)
Expand All @@ -27,8 +34,9 @@ pipeline {
}
stage('Push Docker Image') {
when {
branch 'master'
branch 'development'
}
agent { label agentName }
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'docker_hub_login') {
Expand All @@ -38,15 +46,62 @@ pipeline {
}
}
}
stage('DeployToDev') {
when {
branch 'development'
}
agent { label agentName }
environment {
NAMESPACE = "dev"
NODEPORT = "30050"
}
steps {
kubernetesDeploy(
kubeconfigId: 'kube',
configs: 'train-schedule-kube.yml',
enableConfigSubstitution: true
)
}
}
stage('DeployToCT') {
when {
branch 'development'
}
agent { label agentName }
environment {
NAMESPACE = "ct"
NODEPORT = "30060"
MYIMAGE = "$DOCKER_IMAGE_NAME:$VERSION"
}
steps {
input 'Deploy to CT?'
milestone(1)
kubernetesDeploy(
kubeconfigId: 'kube',
configs: 'train-schedule-kube.yml',
enableConfigSubstitution: true
)
}
}
stage('DeployToProduction') {
when {
branch 'master'
}
agent { label agentName }
environment {
NAMESPACE = "prod"
NODEPORT = "30070"
MYIMAGE = "$DOCKER_IMAGE_NAME:$VERSION"
}
steps {
input 'Deploy to Production?'
milestone(1)
//implement Kubernetes deployment here
kubernetesDeploy(
kubeconfigId: 'kube',
configs: 'train-schedule-kube.yml',
enableConfigSubstitution: true
)
}
}
}
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# cicd-pipeline-train-schedule-kubernetes

# DEV, CT, PROD

This is a simple train schedule app written using nodejs. It is intended to be used as a sample application for a series of hands-on learning activities.

## Running the app
Expand Down
58 changes: 58 additions & 0 deletions train-schedule-kube.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mynamespace
namespace: $NAMESPACE
data:
namespace: $NAMESPACE

---

kind: Service
apiVersion: v1
metadata:
name: train-schedule-service
namespace: $NAMESPACE
spec:
type: NodePort
selector:
app: train-schedule
ports:
- protocol: TCP
port: 8080
targetPort: 8080
nodePort: $NODEPORT

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: train-schedule-deployment
namespace: $NAMESPACE
labels:
app: train-schedule
spec:
replicas: 2
selector:
matchLabels:
app: train-schedule
template:
metadata:
labels:
app: train-schedule
spec:
containers:
- name: train-schedule
image: $MYIMAGE
env:
# Define the environment variable
- name: NAMESPACE
valueFrom:
configMapKeyRef:
# The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
name: mynamespace
# Specify the key associated with the value
key: namespace
ports:
- containerPort: 8080