mirror of
https://github.com/geerlingguy/kubernetes-101.git
synced 2026-08-24 10:13:38 -05:00
Episode 3 Docker container - push to private repo.
This commit is contained in:
@@ -13,12 +13,27 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
# Episode 1.
|
||||
- episode: '01'
|
||||
dockerfile: Dockerfile
|
||||
repo: kube101
|
||||
tag: intro
|
||||
|
||||
# Episode 2.
|
||||
- episode: '02'
|
||||
dockerfile: Dockerfile
|
||||
repo: kube101
|
||||
tag: hello-go
|
||||
- episode: '02'
|
||||
dockerfile: Dockerfile
|
||||
repo: kube101-go
|
||||
tag: '1.0.0'
|
||||
|
||||
# Episode 3.
|
||||
- episode: '03'
|
||||
dockerfile: Dockerfile
|
||||
repo: kube101-go
|
||||
tag: '1.1.0'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@@ -38,4 +53,4 @@ jobs:
|
||||
file: ./episode-${{ matrix.episode }}/${{ matrix.dockerfile }}
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: geerlingguy/kube101:${{ matrix.tag }}
|
||||
tags: geerlingguy/${{ matrix.repo }}:${{ matrix.tag }}
|
||||
|
||||
@@ -9,8 +9,8 @@ name: CI
|
||||
- cron: "40 5 * * 0"
|
||||
|
||||
jobs:
|
||||
episode-2:
|
||||
name: Episode 2
|
||||
hello-go:
|
||||
name: Hello Go
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
@@ -20,6 +20,10 @@ jobs:
|
||||
with:
|
||||
go-version: "1.15.x"
|
||||
|
||||
- name: Run hello Go app tests.
|
||||
- name: Run hello Go app tests (Episode 2).
|
||||
run: go test
|
||||
working-directory: episode-02/cmd/hello
|
||||
|
||||
- name: Run hello Go app tests (Episode 3).
|
||||
run: go test
|
||||
working-directory: episode-02/cmd/hello
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
FROM golang:1-alpine as build
|
||||
|
||||
WORKDIR /app
|
||||
COPY cmd cmd
|
||||
RUN go build cmd/hello/hello.go
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=build /app/hello /app/hello
|
||||
|
||||
EXPOSE 8180
|
||||
ENTRYPOINT ["./hello"]
|
||||
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// HelloServer responds to requests with the given URL path.
|
||||
func HelloServer(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Hi, you requested: %s", r.URL.Path)
|
||||
log.Printf("Received request for path: %s", r.URL.Path)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var addr string = ":8180"
|
||||
handler := http.HandlerFunc(HelloServer)
|
||||
log.Printf("Starting webserver on %s", addr)
|
||||
if err := http.ListenAndServe(addr, handler); err != nil {
|
||||
log.Fatalf("Could not listen on port %s %v", addr, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetHello(t *testing.T) {
|
||||
t.Run("Returns current path", func(t *testing.T) {
|
||||
request, _ := http.NewRequest(http.MethodGet, "/testing", nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
HelloServer(response, request)
|
||||
|
||||
got := response.Body.String()
|
||||
want := "Hi, you requested: /testing"
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user