-
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
0 parents
commit 6b7b528
Showing
13 changed files
with
569 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,39 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
release: | ||
types: [published] | ||
|
||
|
||
jobs: | ||
get-projects: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
projects: ${{ steps.list-projects.outputs.projects }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Get list of Golang project folders | ||
id: list-projects | ||
run: | | ||
set -eux | ||
PROJECTS_JSON=$(find ./golang -maxdepth 1 -mindepth 1 -type d | sed 's|^\./||' | jq -c -R . | jq -s -c .) | ||
echo "projects=$PROJECTS_JSON" >> $GITHUB_OUTPUT | ||
- name: Display JSON output | ||
run: 'echo "Projects: ${{ steps.list-projects.outputs.projects }}"' | ||
|
||
run-jobs: | ||
needs: | ||
- get-projects | ||
strategy: | ||
matrix: | ||
project: ${{ fromJson(needs.get-projects.outputs.projects) }} | ||
uses: ./.github/workflows/golang.yaml | ||
with: | ||
project: ${{ matrix.project }} | ||
secrets: inherit |
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,88 @@ | ||
name: Golang Projects | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
project: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
lint: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22.3' | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
- name: Check formatting | ||
working-directory: ${{ inputs.project }} | ||
run: | | ||
test -z $(gofmt -l .) | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22.3' | ||
- name: Install dependencies | ||
working-directory: ${{ inputs.project }} | ||
run: go get ./src | ||
- name: Build | ||
working-directory: ${{ inputs.project }} | ||
run: go build -o ./dist/bin ./src | ||
- name: Test with the Go CLI | ||
working-directory: ${{ inputs.project }} | ||
run: go test ./src | ||
|
||
build-and-publish-image: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- lint | ||
- build-and-test | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Tag the image | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: | | ||
bitovi/temporal-example-workers | ||
tags: | | ||
type=raw,value=golang-${{ inputs.project }}-latest,enable=${{ github.ref_name == 'main' }} | ||
type=semver,pattern=golang-${{ inputs.project }}-{{version}},enable=${{ github.event_name == 'release' }} | ||
- | ||
name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
if: github.event_name != 'pull_request' | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
- | ||
name: Build Docker image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ${{ inputs.project }} | ||
platforms: linux/amd64,linux/arm64 | ||
tags: ${{ steps.meta.outputs.tags }} | ||
- | ||
name: Push Docker image | ||
uses: docker/build-push-action@v4 | ||
if: ${{ (github.ref_name == 'main') || (github.event_name == 'release') }} | ||
with: | ||
context: ${{ inputs.project }} | ||
platforms: linux/amd64,linux/arm64 | ||
tags: ${{ steps.meta.outputs.tags }} | ||
push: true |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Bitovi | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,7 @@ | ||
# Temporal Worker Examples | ||
|
||
This repo holds examples of Temporal workflows in various languages. | ||
|
||
## Golang | ||
|
||
- [__Hello World__](./golang/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,18 @@ | ||
root = "." | ||
tmp_dir = "tmp" | ||
|
||
[build] | ||
cmd = "go build -o ./tmp/worker worker.go" | ||
bin = "tmp/app" | ||
|
||
full_bin = "./tmp/worker" | ||
log = "air_errors.log" | ||
include_ext = ["go"] | ||
exclude_dir = ["tmp"] | ||
delay = 1000 | ||
|
||
[log] | ||
time = true | ||
|
||
[misc] | ||
clean_on_exit = true |
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,13 @@ | ||
FROM golang:1.22.3 | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
|
||
RUN go mod download | ||
|
||
COPY src/*.go ./ | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux go build -o ./temporal-cloud-autoscaler | ||
|
||
CMD ["./temporal-cloud-autoscaler", "--secure-port=6443", "--cert-dir=/var/run/serving-cert", "--v=10"] |
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,13 @@ | ||
# Please keep up to date with the new-version of Golang docker for builder | ||
FROM golang:1.22.3-bookworm | ||
|
||
RUN apt update && apt upgrade -y && \ | ||
apt install -y git \ | ||
make openssh-client | ||
|
||
WORKDIR /app | ||
|
||
RUN curl -fLo install.sh https://raw.githubusercontent.com/cosmtrek/air/master/install.sh \ | ||
&& chmod +x install.sh && sh install.sh && cp ./bin/air /bin/air | ||
|
||
CMD air |
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,23 @@ | ||
# Temporal Golang Hello World Worker | ||
|
||
This worker simply waits 30 seconds and then returns a string of Hello World. The activity concurrency is set to 1, and the workflow concurrency is set to 2 (this is the minimum value for the [Golang SDK](https://github.com/temporalio/sdk-go/blob/9c422211a412a6a194ecda548f21790ddc66d988/internal/internal_worker.go#L1520-L1526)). | ||
|
||
This example is designed to emulate a resource intensive workflow where only a small number of tasks can run on a given worker, and those tasks take a relatively long time to complete. | ||
|
||
## Usage | ||
|
||
__Startup__ | ||
|
||
```bash | ||
docker compose up -d --build | ||
``` | ||
|
||
__Execution__ | ||
|
||
```bash | ||
temporal workflow start \ | ||
--task-queue=hello-world \ | ||
--type=Workflow \ | ||
--address=localhost:7233 \ | ||
--namespace=default | ||
``` |
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,37 @@ | ||
services: | ||
temporal-dev-server: | ||
container_name: temporal-dev-server | ||
image: debian:buster | ||
command: > | ||
bash -c '\ | ||
apt update && \ | ||
apt install -y curl && \ | ||
curl -sSf https://temporal.download/cli.sh | sh && \ | ||
PATH="\$PATH:/root/.temporalio/bin" >> ~/.bashrc && \ | ||
source ~/.bashrc && \ | ||
temporal server start-dev --namespace default --ip 0.0.0.0 | ||
' | ||
ports: | ||
- 7233:7233 | ||
- 8233:8233 | ||
healthcheck: | ||
test: ["CMD-SHELL", "curl --fail http://localhost:8233/ || exit 1"] | ||
interval: 10s | ||
timeout: 30s | ||
retries: 3 | ||
|
||
worker: | ||
container_name: temporal-worker | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.dev | ||
depends_on: | ||
temporal-dev-server: | ||
condition: service_healthy | ||
restart: always | ||
environment: | ||
- TEMPORAL_PORT=temporal-dev-server:7233 | ||
- TEMPORAL_NAMESPACE=default | ||
- TEMPORAL_QUEUE=hello-world | ||
volumes: | ||
- ./:/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,31 @@ | ||
module temporal-cloud-autoscaler-demo | ||
|
||
go 1.22.1 | ||
|
||
require go.temporal.io/sdk v1.26.1 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/mock v1.6.0 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect | ||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect | ||
github.com/pborman/uuid v1.2.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/robfig/cron v1.2.0 // indirect | ||
github.com/stretchr/objx v0.5.2 // indirect | ||
github.com/stretchr/testify v1.9.0 // indirect | ||
go.temporal.io/api v1.32.0 // indirect | ||
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect | ||
golang.org/x/net v0.24.0 // indirect | ||
golang.org/x/sys v0.19.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
golang.org/x/time v0.3.0 // indirect | ||
google.golang.org/genproto/googleapis/api v0.0.0-20240401170217-c3f982113cda // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect | ||
google.golang.org/grpc v1.63.2 // indirect | ||
google.golang.org/protobuf v1.33.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.