├── Dockerfile ├── README.md ├── .gitlab-ci.yml ├── main.go ├── deployment.yaml └── Vagrantfile /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.11-alpine as builder 2 | WORKDIR /usr/build 3 | ADD main.go . 4 | RUN go build -o app . 5 | 6 | FROM alpine:latest 7 | 8 | WORKDIR /usr/src 9 | 10 | COPY --from=builder /usr/build/app . 11 | EXPOSE 8888 12 | 13 | CMD ["/usr/src/app"] 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-http-hello-world 2 | 3 | ``` 4 | vagrant up 5 | vagrant ssh 6 | ``` 7 | https://docs.gitlab.com/runner/register/index.html 8 | 9 | ``` 10 | docker run -d -p 5000:5000 --restart=always --name registry registry:2 11 | usermod -aG docker gitlab-runner 12 | apt install socat 13 | ``` 14 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: docker:latest 2 | services: 3 | - docker:dind 4 | 5 | stages: 6 | - build 7 | 8 | variables: 9 | CONTAINER_IMAGE: go-http-hello-world:${CI_COMMIT_SHORT_SHA} 10 | 11 | build: 12 | stage: build 13 | script: 14 | - docker build -t ${CONTAINER_IMAGE} . 15 | - docker tag ${CONTAINER_IMAGE} localhost:5000/${CONTAINER_IMAGE} 16 | - docker push localhost:5000/${CONTAINER_IMAGE} 17 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | name, err := os.Hostname() 11 | if err != nil { 12 | panic(err) 13 | } 14 | 15 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 16 | fmt.Fprintf(w, "Hello, World! This is %s.\n", name) 17 | }) 18 | 19 | http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { 20 | fmt.Fprintf(w, "Healthy!") 21 | }) 22 | 23 | http.ListenAndServe(":8888", nil) 24 | } 25 | -------------------------------------------------------------------------------- /deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: go-http-hello-world 5 | spec: 6 | ports: 7 | - port: 8888 8 | selector: 9 | app: go-http-hello-world 10 | 11 | --- 12 | apiVersion: apps/v1 13 | kind: Deployment 14 | metadata: 15 | name: go-http-hello-world 16 | spec: 17 | replicas: 3 18 | selector: 19 | matchLabels: 20 | app: go-http-hello-world 21 | strategy: 22 | type: RollingUpdate 23 | rollingUpdate: 24 | maxSurge: 1 25 | maxUnavailable: 33% 26 | template: 27 | metadata: 28 | labels: 29 | app: go-http-hello-world 30 | spec: 31 | containers: 32 | - name: go 33 | image: localhost:5000/go-http-hello-world:e1c320ee 34 | ports: 35 | - containerPort: 8888 36 | livenessProbe: 37 | httpGet: 38 | path: /healthz 39 | port: 8888 40 | initialDelaySeconds: 2 41 | periodSeconds: 2 42 | readinessProbe: 43 | httpGet: 44 | path: /healthz 45 | port: 8888 46 | initialDelaySeconds: 2 47 | periodSeconds: 2 48 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | $script = <