This repository supports three Kubernetes environments:
| Environment | Branch | Namespace | Local NodePort |
|---|---|---|---|
| Development | dev |
url-shortener-dev |
30080 |
| Stage | stage |
url-shortener-stage |
30081 |
| Production | master |
url-shortener-prod |
30082 |
For now these environments target Docker Desktop Kubernetes. Later, the same layout can be pointed at a cloud Kubernetes cluster by changing image publishing and cluster credentials, while keeping the promotion model.
For one-time Argo CD setup, see Install Argo CD on Docker Desktop Kubernetes.
If the dev and stage branches do not exist yet, create them from
the current stable master branch:
git switch master
git pull origin master
git branch dev
git branch stagePush the branches only after approval:
git push origin dev stageUse this branch flow:
- Create feature work from
dev. - Open feature PRs into
dev. - After
devtesting passes, open a PR fromdevintostage. - After
stagetesting passes, open a PR fromstageintomaster. - Deploy to the production namespace only after
masteris updated and manual approval is given.
Recommended branch names:
feature/<short-description>
Promotion PRs should be small and explicit:
feature/my-change -> dev
dev -> stage
stage -> master
GitHub auto-closes issues only when a closing keyword is merged into the
repository default branch, currently master.
Feature PRs into dev can include Closes #<issue-number> for traceability,
but the final stage -> master promotion PR must also include every issue that
the promotion completes:
Closes #11
Closes #13
Before opening the stage -> master PR, review the merged feature PRs included
in the promotion and copy their related issue references into the promotion PR
body. That ensures GitHub closes the issues automatically when the promotion PR
is merged.
Build the local image before deploying any environment:
docker build -t url-shortener:dev .For non-Kubernetes local development, start the app with:
./scripts/start.shDeploy development:
./scripts/deploy-dev.sh
kubectl port-forward svc/url-shortener 30080:80 -n url-shortener-devThe script builds the local Docker image, applies k8s/environments/dev, and
waits for the dev rollout.
Deploy stage:
./scripts/deploy-stage.sh
kubectl port-forward svc/url-shortener 30081:80 -n url-shortener-stageDeploy production after manual approval:
./scripts/deploy-prod.sh
kubectl port-forward svc/url-shortener 30082:80 -n url-shortener-prodThe production script asks you to type prod before it applies the production
overlay.
Keep the kubectl port-forward command running while you test the app.
The workflow .github/workflows/publish-dev-image.yml builds and pushes a Docker
Hub image when changes are pushed to dev.
The image tag format is:
sunlnx/url-shortener:dev_<short-commit-id>
After pushing the image, the workflow updates
k8s/environments/dev/kustomization.yaml with the new tag and commits that
change back to dev. Argo CD watches the dev branch and deploys the updated
image to the url-shortener-dev namespace.
The workflow .github/workflows/publish-stage-image.yml runs when changes are
pushed to stage, including when a dev -> stage promotion PR is merged. It
builds and pushes:
sunlnx/url-shortener:stage_<short-commit-id>
After pushing the image, the workflow updates
k8s/environments/stage/kustomization.yaml with the new tag and commits that
change back to stage. Argo CD should watch the stage branch and deploy the
updated stage overlay to the url-shortener-stage namespace.
These workflows require these GitHub repository secrets:
DOCKER_HUB_LOGIN: Docker Hub usernameDOCKER_HUB_TOKEN: Docker Hub access token or password
The local deployment scripts are still for Docker Desktop-only manual testing.
They build url-shortener:dev, apply the selected overlay, and override the
Deployment to use the local Docker Desktop image.
Argo CD itself must be installed once in the cluster, and the dev/stage Applications must be created before the branch watcher flow can sync changes. See Install Argo CD on Docker Desktop Kubernetes.
Verify each environment:
curl http://localhost:30080/health # dev
curl http://localhost:30081/health # stage
curl http://localhost:30082/health # prodExpected response:
{"status":"ok"}Do not deploy production as part of an automatic branch push.
GitHub-hosted Actions cannot deploy into Docker Desktop Kubernetes on your machine. While this project targets Docker Desktop, production deployment is a manual local command after approval. When the project moves to a cloud Kubernetes cluster, use GitHub Environments with required reviewers for the production deployment job.
Before production deployment:
- Confirm the
stage -> masterPR is approved and merged. - Confirm CI passed on
master. - Confirm the exact image tag or commit being deployed.
- Get explicit manual approval from the environment owner.
- Run
./scripts/deploy-prod.shonly after that approval.
When moving away from Docker Desktop:
- Continue using unique image tags per commit or release.
- Replace
emptyDirwith persistent storage or a managed database. - Store cluster credentials in GitHub Actions environments or a deployment platform.
- Configure the GitHub
productionenvironment with required reviewers before allowing production deployments.