This is a project in which we made a Go REST API with help of Gin Framework. Additionally, this project contains a CI/CD (Continuous Integration and Continuous Deployment) implementation. It offers a thorough illustration of how to create, test, and deploy a Go application using GitHub Actions and Argo CD.
Follow the steps below, to get started with the project:
- Clone the repository
git clone https://github.com/ShivangShandilya/golang-api.git
- Install the dependencies
go mod download
- Running the Application
go run .
- You can now make GET,POST requests via Thunder Client extension on VS Code or using Postman
- Build the Dockerfile
docker build . -t golang-api
Note: If you're using Docker Desktop, then you can assign any port number of your choice where you want your app to run.
Refer to ci.yaml and publish-dockerhub.yaml files for configuration.
In order for the abpve GitHub Actions to function you must store these inside GitHub secrets of your repository:
DOCKERHUB_USERNAME
- DockerHub UsernameDOCKERHUB_PASSWORD
- DockerHub Password or Access Token
The ci.yaml action consists of 4 steps
-
Checkout Code - This step uses the
actions/checkout@v3
action to clone the repository containing the code that needs to be built and tested. -
Setup Go - This step uses the
actions/setup-go@v4
action to set up the Go programming language environment on the runner. -
Build - This step builds the Go code present in the repository using the go build command. The -v flag enables verbose output, providing additional information during the build process. The . argument indicates that the current directory should be built, assuming it contains the main package of the project.
-
Test - This step runs the tests for the Go code using the go test command. The -v flag again enables verbose output, giving detailed information about the executed tests. The ./tests argument specifies the path to the test directory or package that needs to be tested. It might contain test files with names like *_test.go.
The publish-dockerhub.yaml action consists of 3 steps
-
DockerHub Login - As the name suggests this logs in to the provided DockerHub Account given in the secrets via
DOCKERHUB_USERNAME
andDOCKERHUB_PASSWORD
. -
Build the Docker image - This step builds our Docker Image.
-
Docker Push - Docker Push basically just pushes our image made in previous step over to DockerHub.
A short description for ArgoCD would be - ArgoCD is a Kubernetes-native tool for automating application deployments. It ensures that the deployed applications match the desired state defined in a Git repository, simplifying the management of Kubernetes deployments.
- Start a K8s Cluster locally
minikube start --memory=4098 --driver=docker
- If you don't have Operator Lifecycle Manager (OLM) installed, install from here:
curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.25.0/install.sh | bash -s v0.25.0
- Then follow the steps below
vim argocd-basic.yml
Insert this inside vim editor:
apiVersion: argoproj.io/v1alpha1
kind: ArgoCD
metadata:
name: example-argocd
labels:
example: basic
spec: {}
Now apply this file and check if your pods have started running or not:
kubectl get pods -n operators
-
Change ClusterIP to NodePort for argocd-service and get the external link for the same
-
Now configure your ArgoCD with your project repository and VOILA!!!
- To learn more about Argo CD and configure it in your cluster, refer the documentation.
This project is entirely open-source, if you spot any errors in documnetation or codebase or just wanna suggest an improvement in project, feel free to raise an issue.
This project is licensed under MIT License.