Implementing CodeFresh CI/CD & Docker

Bmwitcher
5 min readOct 31, 2020

Part 2: CI/CD implementation with Docker deploying a static website

In this project, we will use an increasingly popular continuous integration and continuous delivery tool Codefresh.

What is Codefresh?

We often hear about so many different tools that employers use from Jenkins to Ansible to Puppet and Chef it can be overwhelming to try and learn them all. Codefresh is a Continuous Integration/Delivery solution. It fetches code from your GIT repository and packages/compiles it. Then it deploys the final artifact to a target environment. This basic concept is implemented with pipelines.

Before we get logged into Codefresh and implement the CI/CD process let’s build the Dockerfile. I have already completed the file for you below:

The next step is to build our simple HTML file which I have provided below. I would encourage you to make changes in attempts to redirect to another website and the text to make it your own.

One more step before getting logged in to Codefresh. I would encourage you to create a DockerHub account. If you have not set one up please do so now by navigating to: https://hub.docker.com/

After you log in we will click at the top and view repositories:

Next, you will see we have no repositories in our DockerHub account:

Let’s Navigate to Codefresh.io. I will sign in but you can create your free account.

Codefresh will then allow you to log in via multiple SSO providers (Google, Github, Facebook…etc). I would encourage you to use Github and Authorize the actions. It will prompt you a few times to do so.

Once you are logged in, select create new pipeline as you see below:

Next, you will see the options go through the options but as you can see the ease of CodeFresh is that it automatically implements your GitHub repositories and will initiate a GitHub pull request upon creation.

In the above screenshot, you will see the next steps where CodeFresh has generated a YAML file that includes the steps scroll through this file and view the steps to confirm they are correct, then click RUN.

Uh oh 😳, I received an error! Let’s find out why.

It appears I forgot to set up my DockerHub account inside of CodeFresh, lets do that now by navigating to the link shown on your screen.

I opened the link in a new tab.

I will be using Docker Hub however if you have pushed your docker container to Amazon ECR you can use that as well.

Next, you will be prompted to enter your DockerHub credentials. If you enter the master password to your DockerHub account you will receive an error. You must generate an access token inside of your DockerHub account.

Back to Codefresh let’s now navigate back to our pipeline and see if the RUN command works.

It works. Let’s check our DockerHub Repo and see if we have a repository commit yet.

This will now enable us to pull the image from our registry and run the docker container to see our static website/app.

Copy the docker pull command in your terminal or cloud server.

Now we see that we do not have containers running at the moment even though we have pulled the image.

Don’t forget to run the docker login command

Enter in your username

Password: <copy and paste the access token you created earlier>

Let’s view our docker images

We see above our ImageID is 841c0b41d33c. Yours may differ.

Now let’s run a Docker container from the Image ID we pulled earlier

Let’s see if our container is running and functional…Navigate in your browser to localhost:2000

It works… let’s check the link next.

That works as well.

Mission complete! 💫

Let’s stop all containers, remove them and the images. Unless of course, you want to keep them. Follow the below commands:

In summary, we have used the CodeFresh CI/CD tool to build, test, and deploy our Docker image and container. Thanks for reading!

--

--

Bmwitcher

DevSecOps Professional — AWS Certified DevOps Professional/Security Specialty/SA Pro, Gitlab Certified, Terraform Associate GCP-ACE Certfied and more…