first commit

This commit is contained in:
serxoz 2023-09-05 09:43:11 +02:00
commit bbf988c58a
6 changed files with 51 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
main

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
# Compilado
FROM golang:1.21.0 as builder
WORKDIR /
COPY . .
RUN go build -ldflags "-linkmode external -extldflags -static" -a main.go
# Execución
FROM scratch
COPY --from=builder /main /main
EXPOSE 8080
CMD ["./main"]

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
NAME = exemplo
VERSION = 0.0.1
.PHONY: all build run push
all: build
build:
docker build -t $(NAME):$(VERSION) .
run:
docker run -p 8088:8080 --name exemplo $(NAME):$(VERSION)
clean:
docker rm exemplo
docker rmi exemplo:0.0.1
rm ./main

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# exemplo imaxes docker minimas
Exemplo para ilustrar cómo crear imaxes docker mínimas gracias á compilación estática e á imaxen base «scratch».

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module exemplo
go 1.21.0

15
main.go Normal file
View File

@ -0,0 +1,15 @@
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", HelloServer)
http.ListenAndServe(":8080", nil)
}
func HelloServer(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}