-
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.
- Loading branch information
Showing
6 changed files
with
134 additions
and
7 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,49 @@ | ||
name: Build Docker Images for GHCR | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-image: | ||
name: Build Docker Image | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
strategy: | ||
matrix: | ||
include: | ||
- Dockerfile: coffee-shop/coffee-maker/Dockerfile | ||
context: coffee-shop/coffee-maker | ||
tag: coffee-maker | ||
|
||
steps: | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GHCR_PAT }} # Use the new secret here | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: set repository name to lowercase | ||
run: | | ||
echo "reponame=${reponame,,}" >>${GITHUB_ENV} | ||
env: | ||
reponame: '${{ github.repository }}' | ||
|
||
- name: Build and Push Docker Image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: ${{ matrix.context }} | ||
file: ${{ matrix.dockerfile }} | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ghcr.io/une-tasse-de.cafe/${{ env.reponame }}:${{ matrix.tag }} | ||
platforms: linux/amd64,linux/arm64 |
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,12 @@ | ||
FROM golang:1.23.0-alpine3.19 as builder | ||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
COPY . . | ||
|
||
RUN go build | ||
|
||
FROM scratch | ||
COPY --from=builder /app/coffee-maker /app | ||
ENTRYPOINT ["/app"] |
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,11 @@ | ||
|
||
version: '3.8' | ||
services: | ||
coffee-makers: | ||
image: ghcr.io/une-tasse-de-cafe/coffee-shop/coffeemakers:latest | ||
build: . | ||
environment: | ||
- "NATS_URL=192.168.128.51:4222" | ||
deploy: | ||
mode: replicated | ||
replicas: 5 |
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
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
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 |
---|---|---|
@@ -1,30 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/nats-io/nats.go" | ||
"github.com/nats-io/nats.go/jetstream" | ||
) | ||
|
||
const ( | ||
consumerName = "coffeeMakers" | ||
subjects = "coffee.orders.*" | ||
streamName = "coffee-orders" | ||
) | ||
|
||
func main() { | ||
|
||
nc, err := nats.Connect(os.Getenv("NATS_URL")) | ||
natsUrl := os.Getenv("NATS_URL") | ||
if natsUrl == "" { | ||
fmt.Println("Please, provide the NATS URL in NATS_URL") | ||
os.Exit(1) | ||
} | ||
|
||
nc, _ := nats.Connect(os.Getenv("NATS_URL")) | ||
|
||
defer nc.Close() | ||
|
||
js, err := jetstream.New(nc) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer nc.Close() | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
|
||
fmt.Println("waiting for new tasks...") | ||
if _, err = nc.Subscribe("coffee.*", func(m *nats.Msg) { | ||
fmt.Println("New order received") | ||
fmt.Println(string(m.Data)) | ||
cfgStream := jetstream.StreamConfig{ | ||
Replicas: 3, | ||
Name: streamName, | ||
Subjects: []string{subjects}, | ||
Storage: jetstream.FileStorage, | ||
Retention: jetstream.InterestPolicy, | ||
AllowDirect: true, | ||
} | ||
|
||
}); err != nil { | ||
_, err = js.CreateOrUpdateStream(ctx, cfgStream) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
cfgConsu := jetstream.ConsumerConfig{ | ||
Name: consumerName, | ||
FilterSubject: subjects, | ||
Durable: consumerName, | ||
} | ||
|
||
cons, err := js.CreateConsumer(ctx, cfgStream.Name, cfgConsu) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
cc, err := cons.Consume(func(msg jetstream.Msg) { | ||
fmt.Printf("New message from %s : %s - ", msg.Subject(), string(msg.Data())) | ||
msg.InProgress() | ||
time.Sleep(500 * time.Millisecond) | ||
msg.Ack() | ||
fmt.Printf("\n") | ||
}) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer cc.Drain() | ||
|
||
fmt.Println("wait forever") | ||
for { | ||
} | ||
|
||
} |