Building CI/CD Pipeline without Jenkins

Prerequisites

Steps

Please follow the below steps to setup simple CI-CD pipeline with your on-premise servers.

Step 1

First, create a Docker file for your codebase to deploy that in a docker container.

FROM maven:3.6.3-jdk-11-slimENV PROJECT_HOME /mnt/project# add the directory to the path
ADD . /mnt/project
#Add a directory for logs
RUN mkdir -p /mnt/project/logs
# Run maven
RUN cd /mnt/project && mvn clean install
# Expose the port
EXPOSE 8080
# Run the jar file
CMD ["java","-jar","-DlogPath=/mnt/project/logs","/mnt/project/target/simplecicd-1.0.0.jar"]

Step 2

Install docker in your on-premise server.

sudo apt-get update
sudo apt-get remove docker docker-engine docker.io
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
docker --version
docker ps

Step 3

Install webhook to the on-premise server.

https://packages.debian.org/sid/amd64/webhook/downloadwget http://ftp.cn.debian.org/debian/pool/main/w/webhook/webhook_2.6.9-1+b1_amd64.debsudo dpkg -i webhook_2.6.9-1+b1_amd64.deb

Step 4

Create a repository on Docker Hub

Step 5

Add the secrets to GitHub Secrets under repository settings.

  • DOCKER_REPO — address of your repository at Docker Hub
  • DOCKER_USER — Docker Hub username
  • DOCKER_PASS — Docker Hub password

Step 6

Create a GitHub workflow.

name: CI-CD Pipelineon:
push:
branches: [ master ]
jobs:
build:
name: Building the codebase
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
docker:
name: Publish - Docker Hub
runs-on: ubuntu-16.04
needs: [build]
env:
REPO: ${{ secrets.DOCKER_REPO }}
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Login to Docker Hub
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }}
- name: Build Docker image
run: docker build -t $REPO:latest .
- name: Publish Docker image
run: docker push $REPO

Step 7

Go to the GitHub action tab and see the logs on the workflow executing.

Step 8

Now, you need to pull the docker image from the docker HUB and run it in the server.

docker pull sidathweerasinghe/simple-cicd-pipeline:latestdocker run -itd --name demoapp -p 8080:8080 sidathweerasinghe/simple-cicd-pipeline:latest

Step 9

Let’s config the webhook on the server.

[
{
"id": "redeploy-webhook",
"execute-command": "/mnt/scripts/redeploy.sh",
"command-working-directory": "/mnt/scripts"
}
]
#!/bin/sh
docker pull sidathweerasinghe/simple-cicd-pipeline:latest
docker stop demoapp
docker system prune -f
docker run -itd --name demoapp -p 8080:8080 sidathweerasinghe/simple-cicd-pipeline:latest
chmod +x redeploy.sh

Step 10

Run the webhook service and test.

webhook -hooks /mnt/scripts/hooks.json  -verbose &
http://<ip>:9000/hooks/redeploy-webhook

Step 11

Integrate with the GitHub workflow

name: CI-CD Pipelineon:
push:
branches: [ master ]
jobs:
build:
name: Building the codebase
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
docker:
name: Publish - Docker Hub
runs-on: ubuntu-16.04
needs: [build]
env:
REPO: ${{ secrets.DOCKER_REPO }}
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Login to Docker Hub
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }}
- name: Build Docker image
run: docker build -t $REPO:latest .
- name: Publish Docker image
run: docker push $REPO
redeploy:
name: Trigger webhook to Redeploy
runs-on: ubuntu-16.04
needs: [docker]
steps:
- name: Invoke deployment hook
uses: joelwmale/webhook-action@master
env:
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
data: "{ 'myField': 'myFieldValue'}"

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store