-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add demo apps and workflows to build
- Loading branch information
1 parent
e79b919
commit daedf91
Showing
13 changed files
with
417 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
name: Build demo apps | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'apps/**' | ||
|
||
jobs: | ||
hello-world: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: setup qemu | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: setup docker | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: login to ghcr.io | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: docker metadata | ||
uses: docker/metadata-action@v5 | ||
id: hello_world_meta | ||
with: | ||
images: | | ||
ghcr.io/${{ github.repository }}/apps/hello-world | ||
tags: | | ||
type=sha,format=long | ||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | ||
- name: build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: /apps/hello-world | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ${{ steps.hello_world_meta.outputs.tags }} | ||
labels: ${{ steps.hello_world_meta.outputs.labels }} | ||
|
||
probes: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: setup qemu | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: setup docker | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: login to ghcr.io | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: docker metadata | ||
uses: docker/metadata-action@v5 | ||
id: probe_meta | ||
with: | ||
images: | | ||
ghcr.io/${{ github.repository }}/apps/probes | ||
tags: | | ||
type=sha,format=long | ||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | ||
- name: build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: /apps/probes | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ${{ steps.probe_meta.outputs.tags }} | ||
labels: ${{ steps.probe_meta.outputs.labels }} | ||
|
||
blue-green: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: setup qemu | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: setup docker | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: login to ghcr.io | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: docker metadata (blue) | ||
uses: docker/metadata-action@v5 | ||
id: blue_meta | ||
with: | ||
|
||
images: | | ||
ghcr.io/${{ github.repository }}/apps/blue-green | ||
tags: | | ||
type=sha,format=long | ||
type=raw,value=blue | ||
- name: docker metadata (green) | ||
uses: docker/metadata-action@v5 | ||
id: green_meta | ||
with: | ||
images: | | ||
ghcr.io/${{ github.repository }}/apps/blue-green | ||
tags: | | ||
type=sha,format=long | ||
type=raw,value=green | ||
- name: build and push (blue) | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: /apps/blue-green | ||
platforms: linux/amd64,linux/arm64 | ||
build-args: | | ||
IS_BLUE=true | ||
push: true | ||
tags: ${{ steps.green_meta.outputs.tags }} | ||
labels: ${{ steps.green_meta.outputs.labels }} | ||
|
||
- name: build and push (green) | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: /apps/blue-green | ||
platforms: linux/amd64,linux/arm64 | ||
build-args: | | ||
IS_BLUE=false | ||
push: true | ||
tags: ${{ steps.green_meta.outputs.tags }} | ||
labels: ${{ steps.green_meta.outputs.labels }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM golang:1.22 as builder | ||
|
||
ARG IS_BLUE=true | ||
|
||
WORKDIR /go/src/app | ||
|
||
COPY . . | ||
|
||
RUN go mod download | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.IsBlue=${IS_BLUE}" -a -installsuffix cgo -o blue-green . | ||
|
||
FROM debian:bookwork-slim as runtime | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /go/src/app/blue-green . | ||
|
||
CMD [ "/app/blue-green" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/vojtechmares/kubernetes-training/apps/blue-green | ||
|
||
go 1.22.0 | ||
|
||
require github.com/google/uuid v1.6.0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
"strconv" | ||
"text/template" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
var IsBlue string = "true" | ||
|
||
const html = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Hello, Kubernetes! | {{ .Hostname }}</title> | ||
<style> | ||
body { | ||
font-family: Helvetica; | ||
background-color: {{ .Color }}; | ||
color: #fff; | ||
} | ||
pre { | ||
margin: 0.25rem 0; | ||
font-size: 1.5rem; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center;"> | ||
<h1 style="font-size: 4rem;">Hello, Kubernetes! 👋</h1> | ||
<pre>hostname: {{ .Hostname }}</pre> | ||
<pre>instanceID: {{ .InstanceID }}</pre> | ||
</div> | ||
</body> | ||
</html> | ||
` | ||
|
||
func main() { | ||
instanceID := uuid.New().String() | ||
hostname, err := os.Hostname() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
var hexColor string = "#15803d" // green | ||
|
||
isBlue, err := strconv.ParseBool(IsBlue) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if isBlue { | ||
hexColor = "#1d4ed8" | ||
} | ||
|
||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
tpl, err := template.New("index.html").Parse(html) | ||
if err != nil { | ||
log.Println(err) | ||
w.Write([]byte(fmt.Sprintf("Error: %s", err))) | ||
return | ||
} | ||
|
||
err = tpl.Execute(w, map[string]string{"Hostname": hostname, "InstanceID": instanceID, "Color": hexColor}) | ||
if err != nil { | ||
log.Println(err) | ||
w.Write([]byte(fmt.Sprintf("Error: %s", err))) | ||
return | ||
} | ||
|
||
w.Header().Set("Content-Type", "text/html") | ||
}) | ||
|
||
log.Println("Starting server on :8080") | ||
http.ListenAndServe(":8080", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:1.22 as builder | ||
|
||
WORKDIR /go/src/app | ||
|
||
COPY . . | ||
|
||
RUN go mod download | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o hello-world . | ||
|
||
FROM debian:bookwork-slim as runtime | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /go/src/app/hello-world . | ||
|
||
CMD [ "/app/hello-world" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/vojtechmares/kubernetes-training/apps/probes | ||
|
||
go 1.22.0 | ||
|
||
require github.com/google/uuid v1.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
"text/template" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
const html = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Hello, Kubernetes! | {{ .Hostname }}</title> | ||
<style> | ||
body { | ||
font-family: Helvetica; | ||
} | ||
pre { | ||
margin: 0.25rem 0; | ||
font-size: 1.5rem; | ||
} | ||
</style> | ||
</head> | ||
<body style="font-family: Helvetica"> | ||
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center;"> | ||
<h1 style="font-size: 4rem;">Hello, Kubernetes! 👋</h1> | ||
<pre>hostname: {{ .Hostname }}</pre> | ||
<pre>instanceID: {{ .InstanceID }}</pre> | ||
</div> | ||
</body> | ||
</html> | ||
` | ||
|
||
func main() { | ||
instanceID := uuid.New().String() | ||
hostname, err := os.Hostname() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
tpl, err := template.New("index.html").Parse(html) | ||
if err != nil { | ||
log.Println(err) | ||
w.Write([]byte(fmt.Sprintf("Error: %s", err))) | ||
return | ||
} | ||
|
||
err = tpl.Execute(w, map[string]string{"Hostname": hostname, "InstanceID": instanceID}) | ||
if err != nil { | ||
log.Println(err) | ||
w.Write([]byte(fmt.Sprintf("Error: %s", err))) | ||
return | ||
} | ||
|
||
w.Header().Set("Content-Type", "text/html") | ||
}) | ||
|
||
log.Println("Starting server on :8080") | ||
http.ListenAndServe(":8080", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:1.22 as builder | ||
|
||
WORKDIR /go/src/app | ||
|
||
COPY . . | ||
|
||
RUN go mod download | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o probes . | ||
|
||
FROM debian:bookwork-slim as runtime | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /go/src/app/probes . | ||
|
||
CMD [ "/app/probes" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module github.com/vojtechmares/kubernetes-training/apps/probes | ||
|
||
go 1.22.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= |
Oops, something went wrong.