Compare commits

...

8 Commits

6 changed files with 102 additions and 1 deletions

39
Dockerfile Normal file
View File

@ -0,0 +1,39 @@
# Start from the latest golang base image
FROM golang:latest as builder
# Add Maintainer Info
LABEL maintainer="Jan"
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download
# Copy the source from the current directory to the Working Directory inside the container
COPY . .
# Build the Go app
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
######## Start a new stage from scratch #######
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
# Copy the Pre-built binary file from the previous stage
COPY --from=builder /app/main .
# Expose port 8080 to the outside world
EXPOSE 8080
# Command to run the executable
CMD ["./main"]

5
SOLUTION.md Normal file
View File

@ -0,0 +1,5 @@
This document decribes a blue-green deployment using a simple Go web app and Minikube.
To get started, you will need to:
- Install minikube
- Execute `minikube start` to start the cluster

View File

@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: vehicles-blue
spec:
replicas: 3
selector:
matchLabels:
app: vehicles
template:
metadata:
labels:
app: vehicles
version: "1.0"
spec:
containers:
- name: vehicles
image: git.bngrs.net/jan/devops-release:1.0
ports:
- name: http
containerPort: 8080

View File

@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: vehicles-green
spec:
replicas: 3
selector:
matchLabels:
app: vehicles
template:
metadata:
labels:
app: vehicles
version: "1.1"
spec:
containers:
- name: vehicles
image: git.bngrs.net/jan/devops-release:1.1
ports:
- name: http
containerPort: 8080

14
kubernetes/service.yaml Normal file
View File

@ -0,0 +1,14 @@
---
apiVersion: v1
kind: Service # Type of kubernetes resource
metadata:
name: vehicles-service
spec:
type: NodePort # A port is opened on each node in your cluster via Kube proxy.
ports: # Take incoming HTTP requests on port 9090 and forward them to the targetPort of 8080
- name: http
port: 8080
targetPort: 8080
selector:
app: vehicles

View File

@ -18,6 +18,7 @@ var vehicles = []Vehicle{
{ID: "3", Model: "Fiat 500e", Maker: "Fiat"},
{ID: "4", Model: "Peugeot e-208", Maker: "Peugeot"},
{ID: "5", Model: "Volkswagen ID.4", Maker: "Volkswagen"},
{ID: "6", Model: "iX1", Maker: "BMW"},
}
func setupRouter() *gin.Engine {
@ -31,7 +32,7 @@ func setupRouter() *gin.Engine {
func main() {
router := setupRouter()
router.Run("localhost:8080")
router.Run("0.0.0.0:8080")
}
func getHealthz(c *gin.Context) {