- Docker
- Jenkins Server (http://54.254.172.152:8080/) - Address subjected to change as I am currently using the Free Tier AWS which may occassionally go OOM. Please contact me if URL is not accessible. Credentials are sent separately
- Docker-in-Docker (DinD)
- Docker Hub Account and Repository
- Pull source code from Github repository
- Build Docker image and tag it accordingly
- Run the Docker image so that it can be used for additional testing
- Sleep for 10 seconds just to make sure application is ready to accept connections
- Test REST endpoints
- Login to Docker Hub
- Push Docker image to Docker Hub
- Clean up - Stop and remove running container, remove images and logout from Docker Hub
- Launch AWS EC2 Instance for hosting Jenkins server
- Run Jenkins as Docker Container
- Running DinD - Execute the following command from the Jenkins server host:
sudo docker run --name jenkins-docker --rm --detach --privileged --network jenkins --network-alias docker --env DOCKER_TLS_CERTDIR=/certs --volume jenkins-docker-certs:/certs/client --volume jenkins-data:/var/jenkins_home --expose 5656 --publish 2376:2376 --publish 5656:5656 docker:dind --storage-driver overlay2
- I have added an additional step to test the REST endpoint before pushing the images to Docker Hub. Due to this, it is required to also expose port 5656 from the DinD container so that it can be reached from the Jenkin server container
- Access Jenkins UI (http://54.254.172.152:8080/) and login using the given credentials
- From the Jenkins Dashboard, select "New Item" from the sidebar
- Enter the item name and select "Pipeline". Click "OK" to confirm
- From the "Configure" page, select "Advanced Project Options" from the sidebar. Under the "Pipeline" tab, copy the content from the Jenkinsfile into the script box
- While the recommended approach would be to reference the Jenkinsfile instead of inputing the content within the script field, I opted for this approach due to the simplicity of the pipeline configuration. May improve this in future if there is a need to
- Login to your Docker Hub account
- Select your profile and open "Account Settings"
- From the "Account Settings" page, open "Personal access tokens" under the "Security" Tab
- Enter a description for the access token and enable "Read & Write" permissions
- Copy the displayed access token
- Navigate to the "Home" page of the Jenkins server. Under the sidebar, select "Manage Jenkins"
- Select "Credentials". Under the "Credentials" tab, select "System"
- Select "Global credentials (unrestricted)"
- Enter your Docker Hub username into the "Username" field and paste the newly created access token into the "Password" field. Save the credential
- From the Jenkin Dashboard, select the newly created Pipeline
- From the sidebar, select "Build Now"
- Monitor build status from the "Build History" tab