Simple and Tested HTTP Server in Go for CI Experimentations.
This repository contains a simple HTTP server implemented in Go, designed for CI experimentations. The server includes features such as Dockerfile configuration, end-to-end tests using Playwright, unit testing, an endpoint with a database connection, deployment with Kustomization in staging and production environments, and support for canary deployment.
-
HTTP Server in Go: A basic HTTP server written in Go to serve as a foundation for CI experiments.
-
Dockerfile: Includes a Dockerfile for containerizing the Go application.
-
End-to-End Tests with Playwright: Provides end-to-end tests using Playwright to ensure the reliability of the application.
-
Unit Testing: Includes unit tests for the Go codebase.
-
Database Connection: Demonstrates an endpoint with a database connection for more realistic scenarios.
-
Deployment with Kustomization:
- Configurations for staging and production environments using Kustomize.
- Secrets for sensitive information like
DATABASE_PASSWORD
and private registry credentials.
-
Canary Deployment: Supports canary deployments for gradual rollouts.
Before you begin, ensure you have the following:
- Docker
- Kubectl for deploying to Kubernetes clusters.
- Kustomize for customizing Kubernetes manifests.
Before deploying, make sure to configure the necessary secrets:
-
DATABASE_PASSWORD:
-
Create a secret named
database-secret
in your Kubernetes cluster with the keyDATABASE_PASSWORD
. Update the value accordingly.kubectl create secret generic database-secret --from-literal=DATABASE_PASSWORD=your_password_here
-
-
Private Registry Credentials:
-
Create a secret named
registry-secret
in your Kubernetes cluster with the Docker registry credentials. You can create the.dockerconfigjson
file and then create the secret using:kubectl create secret generic registry-secret --from-file=.dockerconfigjson=/path/to/your/.dockerconfigjson
Ensure that your
.dockerconfigjson
contains credentials for your private Docker registry. -
-
Clone the repository:
git clone https://github.com/michaelahli/octopus.git cd octopus
-
Build the Docker image:
docker build -t octopus:latest .
-
Run the Docker container:
docker run -p 8080:8080 -e DATABASE_PASSWORD=your_database_password -d octopus:latest
Replace
your_database_password
with the actual database password. -
Access the application at http://localhost:8080.
Deploy to the staging environment using Kustomize:
cd deploy/overlays/staging
kustomize edit set image host.docker.internal:30500/octopus=host.docker.internal:5000/octopus:latest
kustomize build | kubectl apply -f -
Deploy to the production environment using Kustomize:
cd deploy/overlays/production
kustomize edit set image host.docker.internal:30500/octopus=host.docker.internal:5000/octopus:latest
kustomize build | kubectl apply -f -
For canary deployment, modify the Kustomization file in the k8s/canary
directory as needed and apply the changes:
cd deploy/overlays/canary
kustomize edit set image host.docker.internal:30500/octopus=host.docker.internal:5000/octopus:latest
kustomize build | kubectl apply -f -