Containerizing Go + React & Automating w/ GitHub Actions | Part 2
Part 1: Containerizing Go + React
Part 2: Automating w/ GitHub Actions + Pushing to Docker Hub
Recap 🐟
We have a Go Fiber Application serving a React Application. The goal is to automate the containerize + push to Docker Hub steps by developing a GitHub workflow.
See part 1 for containerization. Demo Application is provided at the end.
Getting Started 🔫
The folder structure of the demo application is:
├───mocktail-dashboard
│ ├───package.json
│ ├───....
│
├───mocktail-api
│ ├───Dockerfile
│ ├───...
According to the folder structure, React application is built under mocktail-dashboard, and we need it under mocktail-api before containerization.
Instructions
- Build the React Application
- Have it under mocktail-api
- Build Docker Image
- Push to Docker Hub
Workflow ⬇
Workflow Summary (Will be triggered whenever the master branch is updated)
- Checkout & build the React application under mocktail-dashboard.
- Upload the build folder using actions/upload-artifact@v2
- Switch to the second job, Checkout and download the artifact using actions/download-artifact@v2
- Build the docker image
- Log in to Docker Hub (generate an access token instead of using your Docker Hub password & create a repository secret, keeping your secrets secret is an important habit. Do not hardcode or log)
- Tag the image with short commit sha & “latest” and push to Docker Hub.
Thank you for reading. Feel free to contact me if you have any questions or suggestions. https://hhaluk.me
Cheers! 🎉