This project aims to demonstrate how to build a Continous integration pipeline to automatically build and push a docker image to docker hub whenever a push is made to the repository.
Note: this assumes you have a working knowlege of git, docker and github actions
https://docs.docker.com/get-docker/
-
Clone the project repository by running:
git clone <REPO_URL>
-
Navigate to the nginx-website folder by running:
cd nginx-website-docker
-
Build the docker image by running:
docker build -t <your_username>/nginx-website:latest .
Note: this assumes the Dockerfile is in the directory you are running this command
-
Run the newly built image to check out the website in a browser
docker run -p 80:80 <your_username>/nginx-website
This creates a new container from the image and binds port 80 of the container to port 80 of the host machine
-
Visit
http://localhost
to view the websiteClick
ctrl+c
to stop the running containerNote: I did not make this website but got it as a template on bootstrapmade.com
GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.
https://docs.github.com/actions
We just have a basic pipeline with one job named docker
The pipeline has been configured to run everytime a push is made to the master branch
-
Checkout: The
checkout
action is used to checkout the source code -
Setup docker buildx: The
setup-buildx-action
is used to set up docker buildx on the runner -
Dockerhub login: The dockerhub username and password are gotten from the repository secrets and used to login to dockerhub
-
Build and push: Finally, the
build-push-action
builds the image from the Dockerfile and pushes it to docker hub
The pipeline lives in a file called nginx-website-docker
which, according to github actions specifications, lives in the .github/workflows
folder.
The pipeline runs automatically whenever a push is made to the master branch
You can view the pushed image in your dockerhub account
And there you have it. We have succesfully implemented a CI/CD pipeline with github actions.
Need a devops or SRE engineer to join your team? Send me an email at [email protected]