Testing auto deploy
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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"mime"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/drone-example/foo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var a, b int
|
||||
|
||||
fmt.Printf("a = ")
|
||||
if _, err := fmt.Scanln("%d", &a); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("b = ")
|
||||
if _, err := fmt.Scanln("%d", &b); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
result := foo.Sum(a, b)
|
||||
log.Printf("a + b = %v", result)
|
||||
r := http.NewServeMux()
|
||||
r.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
aStr := r.URL.Query().Get("a")
|
||||
bStr := r.URL.Query().Get("b")
|
||||
|
||||
a, err := strconv.Atoi(aStr)
|
||||
if err != nil {
|
||||
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…
Reference in New Issue