Compare commits
8 Commits
69d6ba18a9
...
8a7195a4c8
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a7195a4c8 | |||
| f7c3ff60ab | |||
| c396eddc90 | |||
| 48be65e46d | |||
| b99b9e85ee | |||
| 00839644bb | |||
| cd44b1b193 | |||
| 0d9019bfc9 |
39
Dockerfile
Normal file
39
Dockerfile
Normal 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
5
SOLUTION.md
Normal 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
|
||||
21
kubernetes/deployment-blue.yaml
Normal file
21
kubernetes/deployment-blue.yaml
Normal 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
|
||||
21
kubernetes/deployment-green.yaml
Normal file
21
kubernetes/deployment-green.yaml
Normal 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
14
kubernetes/service.yaml
Normal 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
|
||||
|
||||
3
main.go
3
main.go
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user