Leveraging GitHub Actions, Docker, Code Quality, and Slack Integration
Tags: devops, tutorial, docker, githubactions
Published: 2024-04-01 03:53:30

**📌Prerequisites:**
- [Github account](https://github.com/)
- [Dockerhub account](https://hub.docker.com/)
- Web repository for dockerize

>_The web repository could be any of you wish_

##🎯Workflow 
1️⃣Build🧱 & Test🧪 
2️⃣Dockerize🐳 the web project
3️⃣Upload💹 image to your docker hub account

---
## 1️⃣Build🧱 & Test🧪
Why do what others have already done?
>_Github Actions has a marketplace where you can find🔎 any pipeline that any other developer has developed._

 **Writing✏ the pipeline**
- Inside repo -> Click in **Actions**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fph6szm4dyh79mb9b37r.png)
- Create the workflow -> Enter **New workflow**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lyc563l7v5tiyf8yy0f5.png)

- Search for a NodeJs pipeline

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9haxwuf6dwpazhhgyemq.png)

- Adjust the pipeline to your needs
An example of my [pipeline ](https://github.com/Sharker3312/Node-App/actions/runs/8445740088/workflow)stages

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jnve0nb5tchopev8szhx.png)


## 2️⃣Dockerize🐳 the web project

>_So, if you want to contain the application, you just have to write a dockerfile_

🚨 Packing the NodeJs project

- Create a _dockerfile.ci_  at the root project directory


```bash
FROM node:18-alpine
WORKDIR /usr/src/app

COPY package.json package-lock.json ./
COPY app.js ./
COPY views ./views/

RUN npm install
#web port
EXPOSE 8000
CMD ["node", "app.js"]
```



## 3️⃣Upload💹 image to your docker hub account
- Go to github [marketplace](https://github.com/marketplace)🛒
- Looking for build and push dockerhub

I like this pipeline

```bash
#Name of Job
 to_dockerhub:
    runs-on: ubuntu-latest
    #Wait for ending test process
    needs: test

    steps:
    
    - uses: actions/checkout@v3
      name: Check out code

    - uses: mr-smithers-excellent/docker-build-push@v6
      name: Build & push Docker image
      with:
        #Name's dockerhub / Name as you want
        image: sharker3312/nodeapp
        tags: v1, latest
        registry: docker.io
        dockerfile: Dockerfile
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}
```
**Create the secret for login**
- Go to Settings

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z54j9j18hhh2abh49g6h.png)

- In left panel Click 
- **Secrets and Variables** -> **Actions**



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4yw4u45qctdtjnw72l1l.png)

- Enter the secrets

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/znmhirglzykbjo18an9h.png)

---
🎬Run the workflow

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jwwd7xmy5o40topbv1gj.png)

---


🔦Check the dockerhub repository

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7meqqs2z7lwdkqtpqjt.png)

Done✅🚀

---
<a href="https://linkedin.com/in/lesterdprez" rel="nofollow"><img src="https://camo.githubusercontent.com/d94940866c98cb4fca5783c4e8ac95776d2f52df6bbf3d5ab9e30d76836f30ae/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c696e6b6564496e2d2532333030373742352e7376673f6c6f676f3d6c696e6b6564696e266c6f676f436f6c6f723d7768697465" alt="LinkedIn" data-canonical-src="https://img.shields.io/badge/LinkedIn-%230077B5.svg?logo=linkedin&amp;logoColor=white" style="max-width: 100%;"></a>