📌Prerequisites:
- Github account
- Dockerhub account
- 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
- Adjust the pipeline to your needs An example of my pipeline stages
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
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🛒
- Looking for build and push dockerhub
I like this pipeline
#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
- In left panel Click
- Secrets and Variables -> Actions
- Enter the secrets
🎬Run the workflow
🔦Check the dockerhub repository
Done✅🚀
Top comments (0)