diff --git a/department-service/Dockerfile b/department-service/Dockerfile new file mode 100644 index 0000000..f2dce0f --- /dev/null +++ b/department-service/Dockerfile @@ -0,0 +1,10 @@ +from node as build +copy index.js /src/ +copy package* /src/ +run cd /src && \ + npm install +from node +copy --from=build /src/node_modules /dist/node_modules/ +copy index.js /dist/ +workdir /dist +cmd ["node", "index.js"] diff --git a/department-service/Jenkinsfile b/department-service/Jenkinsfile new file mode 100644 index 0000000..9111366 --- /dev/null +++ b/department-service/Jenkinsfile @@ -0,0 +1,75 @@ +pipeline { + agent { + kubernetes { + yaml """ +apiVersion: v1 +kind: Pod +metadata: + labels: + service_name: department-service + service_type: REST +spec: + containers: + - name: dnd + image: docker:latest + command: + - cat + tty: true + volumeMounts: + - mountPath: /var/run/docker.sock + name: docker-sock + - name: kubectl + image: bryandollery/terraform-packer-aws-alpine + command: + - cat + tty: true + volumes: + - name: docker-sock + hostPath: + path: /var/run/docker.sock + type: Socket +""" + } + } + environment { + CREDS = credentials('bryan_docker_creds') + DOCKER_NAMESPACE = 'bryandollery' + SERVICE_NAME = 'department-service' + TOKEN=credentials('tester_token') + } + stages { + stage("Build") { + steps { + container('dnd') { + sh ''' + cd $SERVICE_NAME + docker build --tag $DOCKER_NAMESPACE/$SERVICE_NAME . + ''' + } + } + } + stage("Release") { + steps { + container('dnd') { + sh ''' + docker login -p $CREDS_PSW -u $CREDS_USR + docker push $DOCKER_NAMESPACE/$SERVICE_NAME + ''' + } + } + } + stage("Deploy") { + steps { + container('kubectl') { + sh ''' + cd $SERVICE_NAME + kubectl --token=$TOKEN -n test get all + kubectl --token=$TOKEN -n test apply -f deploy.yaml -f service.yaml + kubectl --token=$TOKEN -n test get all + + ''' + } + } + } + } +} diff --git a/department-service/Makefile b/department-service/Makefile index fd7f50e..04b3a74 100644 --- a/department-service/Makefile +++ b/department-service/Makefile @@ -1,4 +1,7 @@ build: - docker build --tag department-service .build -run: - docker run -it --rm -p 8082:80 department-service \ No newline at end of file + docker build --tag $$DOCKER_NAMESPACE/$$SERVICE_NAME . + +release: + docker login -p $$CREDS_PSW -u $$CREDS_USR + docker push $$DOCKER_NAMESPACE/SERVICE_NAME + diff --git a/department-service/deploy.yaml b/department-service/deploy.yaml new file mode 100644 index 0000000..07cdd01 --- /dev/null +++ b/department-service/deploy.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: department-service + labels: + app: department-service + type: api +spec: + replicas: 1 + selector: + matchLabels: + app: department-service + template: + metadata: + labels: + app: department-service + spec: + containers: + - name: department-service + image: bryandollery/department-service + ports: + - containerPort: 80 diff --git a/department-service/readme.md b/department-service/readme.md index bc06563..c8ed43e 100644 --- a/department-service/readme.md +++ b/department-service/readme.md @@ -1,9 +1,10 @@ ## A nodejs REST service to return departments +### Simple API to provide a service for the DevOps Bootcamp -Designed to run in a node:lts-alpine3.10 container +Designed to run in a node container Exposes an http service endpoint on port 80 with the /department/ context path eg -http://{host}/department/ \ No newline at end of file +http://{host}/department/ diff --git a/department-service/service.yaml b/department-service/service.yaml new file mode 100644 index 0000000..bd27473 --- /dev/null +++ b/department-service/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: department-service +spec: + type: NodePort + selector: + app: department-service + ports: + - port: 80 + targetPort: 80 diff --git a/readme.md b/readme.md index 3eb39f8..010e79d 100644 --- a/readme.md +++ b/readme.md @@ -54,7 +54,8 @@ Once the builds are successful, the same pipeline can deploy the app to kubernet Each of the 5 services needs a separate deployment and service object definition. Your services should expose NodePorts so that they can be accessed from your browser. The complexity here is that you need to have known port for each service otherwise you will not be able to access it from the UI. -Remember, the calls to the separate REST services are made from the browser, not from the UI service. +Remember, the calls to the separate REST services are made from the browser, not from the UI service. +There is no inter-service chatter.