GitHub Actions Tutorial | CI Pipeline with Docker
Tags: github, tutorial, webdev, devops
Published: 2020-10-08 15:27:14

##Overview of what you learn 🧠 👏🏻 ##
With this complete [GitHub Actions Tutorial](https://youtu.be/R8_veQiYBjI)  🎬  you'll get a good overview of:
- what GitHub Actions actually is, 
- understand specific developer **workflow use cases** that you can automate with GitHub Actions 
- how GitHub Actions works - basic concepts including GitHub **Events, Actions and workflow**
- the most common workflow, which is **CI/CD pipeline**
- understand why it's not just another ci/cd tool or what are the **benefits of GitHub Actions CI CD pipeline**
- **hands-on demo**, where I explain the **syntax of github actions workflow file** and then I show you a complete ci pipeline setup with my example Java Gradle project, which we will **build into a Docker Image** 🐳 and **push** to a private Docker repository on DockerHub.

## What is GitHub Actions? 🤔 ##
GitHub Actions is a platform to **automate developer workflows**.
Many tutorials seem to convey that GitHub Actions is a ci/cd tool, but **CI/CD is just one of many workflows**.

*What is CI/CD?*
>**C**ontinuous **I**ntegration: integrate developer's code into a shared repository. Each check-in is then verified by an automated build.
>**C**ontinuous **D**elivery picks up where continuous integration ends and automates the delivery of applications to infrastructure environments.

So, what are those developer workflows? 👀

## Developer Workflow Use Cases 👩🏻‍💻 ##
Some specific organizational tasks, that GitHub Actions can automate e.g. for a maintainer of an open source project:
![Developer workflow use cases](https://dev-to-uploads.s3.amazonaws.com/i/bysed3xtz1x8qb0b9gw2.png)

All these tasks are workflow examples of what you have to do as a maintainer of a GitHub repository.
The bigger the project gets and the more contributers you get and the more features, issues and pull requests are created, the more organizational effort you have 😦 .

And of course, as a developer you'd rather code and instead **automate as much as possible** of those management tasks!

For that purpose GitHub Actions was created 💡.

Obviously not everybody has an open source project on GitHub, so for your private project the **most common workflow** will be a **CI/CD pipeline**.

## How GitHub Actions works - Events, Actions and Workflows ##

Every time when something happens IN or TO your repository (**Events**) you can configure automatic actions to be executed in response (**Actions**).

![GitHub Events, Actions and Workflows](https://dev-to-uploads.s3.amazonaws.com/i/4xqiy7pgr11uytbx40ez.png)

GitHub Actions are individual tasks, combined they result in a custom **workflow** 🔁.

So, how does this translates to the actual config file.

----

#### Workflow config file ###

Creating a workflow file:
![GitHub Actions](https://dev-to-uploads.s3.amazonaws.com/i/ctuuqjoov65drxgu9p91.png)

Your config file is a "workflow" of **triggers ("on" - the events)** and **steps**. You can have as many steps as you want. 

These steps can be a combination of:
- shell commands - "run" (like *npm run build, ./gradlew build, ...*)
- external actions - "uses"

![GitHub Actions Workflow File](https://dev-to-uploads.s3.amazonaws.com/i/vd8rlge2n42j92k8vemp.png)

#### Actions ####
An external action is just a repo with actions.yml file published by the community, which is reusable for you.

So, it's a reusable flow which you can use like a library. You can find actions available in the [Actions "marketplace"](https://github.com/marketplace).

#### Jobs ####
The job is the **"what" actually executes**. You can name the job anything, but you only need one job in most cases.

The syntax of the workflow config file is YAML. [Full YAML Tutorial here](https://youtu.be/1uFVr15xDGg)

----

> Tip 💡: GitHub has a big list of workflow templates, so you don't have to write your workflow file from scratch. Use one of the templates that matches the technology your project uses.

![Workflow templates](https://dev-to-uploads.s3.amazonaws.com/i/ubem35lej7zq517qrq0d.png)

--------
These are just the key parts, you can watch the full tutorial for more detailed explanations.

Now let's look at a specific workflow example.

## CI/CD with GitHub Actions ##
A simple CI/CD pipeline could look like this: You commit your code, the build starts, you *test* your code, you *build* your code into an artifact, *push* the artifact in some storage and then *deploy* the app to a deployment server.

####Just another CI/CD tool? 🙄 ####
Why is it a big deal to have just another CI/CD tool? Because 
there are already well established ones like Jenkins.

Benefits:
- 👍 It's integrated in your code repository. If you're already hosting your code on GitHub, now you can use the same tool instead of setup integration with another third-party CI/CD tool
- 👍 The setup of the pipeline is **easy**
- 👍 It's a tool meant for developers

#### Integration with other technologies 🚀 ####
So, *why is the setup easier?* 🧐
To understand that you must know, that one of the most important things when setting up a CI/CD pipeline is its integration with different tools and technologies.

Just look at these **2 simple pipelines**: 
![CI/CD Pipeline Example 1](https://dev-to-uploads.s3.amazonaws.com/i/0t825ivvorl8vohbvr9d.png)

![CI/CD Pipeline Example 2](https://dev-to-uploads.s3.amazonaws.com/i/3z8535y6v4ngners7h1y.png)

You don't want to configure each and every integration with those tools, like installing Java, Maven and Docker, integrations with Nexus, AWS, installing plugins and so on.

Instead you want a simpler way of saying:
*"I want an environment with Node and Docker already available, with a version I want."* And in the same way the deployment part should be easy by simply connecting to the target environment and deploying the application there.

That's exactly the advantage when using GitHub Actions! 🤩

## DEMO 👩🏻‍💻 ##
In the below video in the demo part I show and explain how it works step by step.

Using an example Java Gradle project, which we will build into a Docker Image (because we live in a world of containerization 🐳) and push to a private Docker repository (DockerHub).

![GitHub Action CI pipeline demo](https://dev-to-uploads.s3.amazonaws.com/i/5yttlk0al3fhn88spt57.png)

Watch the full video here 🤓
{% youtube R8_veQiYBjI %}

-----------------
► Get **30% off** - with this code: UDEMY_NANA_NOV2020: [Udemy course here](https://bit.ly/35qF26i)
► **Kubernetes 101**: [Compact and easy-to-read ebook bundle 🚀](https://www.techworld-with-nana.com/e-books) 
It's a handy way to quickly look something up or refresh your knowledge at work and use it as your cheatsheet  😎


**Like, share and follow me** 😍 for more content:
- [Private FB group](https://www.facebook.com/groups/techworldwithnana)
- [Twitter](https://twitter.com/Njuchi_)
- [YouTube](https://www.youtube.com/channel/UCdngmbVKX1Tgre699-XLlUA?sub_confirmation=1)
- [Instagram](https://www.instagram.com/techworld_with_nana/)
- [LinkedIn](linkedin.com/in/nana-janashia)