Skip to content

Instantly share code, notes, and snippets.

@pebcac
Last active January 15, 2024 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pebcac/985713af5e9f2f4a858c8a0964200541 to your computer and use it in GitHub Desktop.
Save pebcac/985713af5e9f2f4a858c8a0964200541 to your computer and use it in GitHub Desktop.
Generic makefile template for an OpenShift app deployment
# Makefile for OpenShift/Kubernetes Deployment
# Define variables
NAMESPACE := test
IMAGE_NAME := your-image-name
IMAGE_TAG := latest
DOCKER_REGISTRY := your-docker-registry
# Default target
all: deploy
# Deploy everything
deploy: deploy-sa deploy-role deploy-rolebinding deploy-app
# Deploy Service Account
deploy-sa:
oc apply -f serviceaccount.yaml
# Deploy Role
deploy-role:
oc apply -f role.yaml
# Deploy RoleBinding
deploy-rolebinding:
oc apply -f rolebinding.yaml
# Deploy Application
deploy-app:
oc apply -f deployment.yaml
oc apply -f service.yaml
# Build and push Docker image
build-push-image:
podman build -t $(DOCKER_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) .
podman push $(DOCKER_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
# Run Tests
test:
kubectl -n $(NAMESPACE) get all
@echo "Running additional tests..."
# Here you can add your specific tests (e.g., curl for checking a web service)
# Clean up resources
clean:
oc delete -f deployment.yaml
oc delete -f service.yaml
oc delete -f rolebinding.yaml
oc delete -f role.yaml
oc delete -f serviceaccount.yaml
# Help
help:
@echo "Makefile for deploying and managing OpenShift/Kubernetes resources"
@echo ""
@echo "Usage:"
@echo " make deploy - Deploy all resources to the cluster"
@echo " make build-push-image - Build and push Docker image"
@echo " make test - Run tests"
@echo " make clean - Delete all deployed resources"
@echo " make help - Show this help message"
.PHONY: deploy deploy-sa deploy-role deploy-rolebinding deploy-app build-push-image test clean help
@pebcac
Copy link
Author

pebcac commented Jan 15, 2024

Modified template to use "oc" and "podman"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment