Testing auto deploy

main
Antonio De Lucreziis 2 years ago
parent d5aa458af7
commit a3021c7475

@ -1,9 +0,0 @@
kind: pipeline
name: default
steps:
- name: test
image: golang
commands:
- go test -v ./...
- go build -o ./bin/drone-example .

@ -0,0 +1,35 @@
kind: pipeline
name: default
steps:
- name: test
image: golang
commands:
- go test -v ./...
- go build -v -o ./bin/drone-example .
---
kind: pipeline
name: deploy
steps:
- name: deploy
image: docker:cli
volumes:
- name: docker-socket
path: /var/run/docker.sock
commands:
- docker build -t drone-example .
- docker rm -f drone-example
- docker run -d -p 127.241.212.77:1098 --restart always --name drone-example drone-example
volumes:
- name: docker-socket
host:
path: /var/run/docker.sock
trigger:
event:
- promote
target:
- production

@ -0,0 +1,11 @@
FROM golang:latest
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
RUN go build -v -o ./bin/drone-example .
CMD ["./bin/drone-example"]

@ -1,24 +1,46 @@
package main package main
import ( import (
"fmt" "encoding/json"
"log" "log"
"mime"
"net/http"
"strconv"
"git.phc.dm.unipi.it/phc/drone-example/foo" "git.phc.dm.unipi.it/phc/drone-example/foo"
) )
func main() { func main() {
var a, b int r := http.NewServeMux()
r.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("a = ") if r.Method != http.MethodGet {
if _, err := fmt.Scanln("%d", &a); err != nil { http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
log.Fatal(err) return
} }
fmt.Printf("b = ")
if _, err := fmt.Scanln("%d", &b); err != nil { aStr := r.URL.Query().Get("a")
log.Fatal(err) bStr := r.URL.Query().Get("b")
}
a, err := strconv.Atoi(aStr)
result := foo.Sum(a, b) if err != nil {
log.Printf("a + b = %v", result) http.Error(w, `the query param "a" must be an integer`, http.StatusUnprocessableEntity)
return
}
b, err := strconv.Atoi(bStr)
if err != nil {
http.Error(w, `the query param "b" must be an integer`, http.StatusUnprocessableEntity)
return
}
result := foo.Sum(a, b)
w.Header().Set("Content-Type", mime.TypeByExtension(".json"))
if err := json.NewEncoder(w).Encode(result); err != nil {
log.Fatal(err)
return
}
})
log.Fatal(http.ListenAndServe(":5000", r))
} }

Loading…
Cancel
Save