Tweet app revisited to build, test, deploy using an automated CI-CD pipeline with Wercker deployed as containers on AWS.
This post is to help you set up a CI-CD pipeline using wercker for the application running on docker container. Same can be used to scale out or for bigger applications as well. It would serve as a initial starting point to set up pipeline and workflows on wercker.
This would also help you with Slack integration step to post notifications on your build status.
The application would have this structure;
- Dockerhub Account to store your docker images – create your free docker hub account
- Wercker Account for your CI-CD pipeline – create your free wercker account
- A running EC2 Instance. ( Note: Install docker on the EC2 Server )
Application: A simple html page with your content and a tweet icon invoking actionable tweet icon. Source code for the application including the wercker.yml file.
- Integrating werkcer with git – On the profile page, open up setting and git connections underneath settings. You would have option to either connect to your github account or bitbucket account.
- Creating the application. Click on the + icon on top right corner to see an option named create an application. Once you click on it, it will auto populate the repositories in the git hub account you had linked earlier. Choose the code repository that you would like to configure the CI pipeline. Configure the access and your application will be created. you are all done!
- Create the pipelines : Pipelines are collection of steps. While steps are the single logical chunk or block of code, pipeline is the collection of such steps. It could involve building a docker image step, notifying a slack channel as the build pipeline.
4. Create the workflows: Workflow is the flow of pipelines. Workflows determine which order the pipelines get executed. We could align them in series or parallel. One example could be multiple tests that could happen at the same time and all the test pipelines could be aligned in parallel. While deploy step could be aligned in series after the build step.
5. Managing environment variables: Environment variables can be managed at organization level ( highest account level), it could be managed at application level or at a pipeline level as well. Often times top order names are managed at organization level, while application related environment variables are maintained at application level.
Some of the variables we would use are these:
- Dockerhub username and password
- key information.
Wercker provides masking or encrypting the passwords. Once masked it will only be open at the run time invoking of the variable, thus providing an added security layer.
Lets now define the wercker.yml
This is the file maintained in a declarative yaml which controls all the steps, pipelines.
Most of the work happens because of the declarations in the wercker.yml. We can include multiple pipelines like build, test, push to dockerhub and deploy to each environments inside of the wercker.yml file.
The build section contains basic install test as of now. You could add in more tests as per the need. The build section also contains the slack integration, which will post notifications to your slack channel. You will have to configure incoming webhook on slack.
The push to docker contains the syntax declarations on how we push the container to Dockerhub. The deploy section contains commands to show how we deploy the docker image.
Most importantly note the steps being used. We are using predefined steps which have been developed by the community and by wercker organization.
Highly notable integrations are internal-push for pushing the image to the container registry ( consider it as a github for docker images ).
Slack notifier step, which integrated wercker with slack to post notifications about build step.
ssh key addition, this would help us use ssh keys to authenticate and login to EC2 servers.
In the environment variable section, you can create SSH keys.
Once you have generated the keys, you can then go ahead and copy the public key and paste it in the authorized_keys in .ssh directory inside of the home directory of the user you are going to use to login to the EC2 server. Note: we are going to ssh into the instance and do certain commands for our deploy step.
With these resources, you can now get started on wercker.
Have a great start to creating your first pipeline. Keep following the blog for more articles to follow and more refinement on this article too.
AUTHOR: Ravi Devatha