Skip to content

Commit c26d63f

Browse files
committed
docker: Add hello world workflow sample with k8s config
Add containerized hello world workflow with Dockerfile and k8s deployment manifest. Signed-off-by: Diana Zawadzki <[email protected]>
1 parent 09ba7f3 commit c26d63f

File tree

19 files changed

+1679
-0
lines changed

19 files changed

+1679
-0
lines changed

docker/.devcontainer/Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM mcr.microsoft.com/devcontainers/go:1.23
2+
3+
# Install additional tools
4+
RUN apt-get update && apt-get install -y \
5+
git \
6+
make \
7+
curl \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Set up workspace
11+
WORKDIR /workspace
12+
13+
# Install Go tools
14+
RUN go install golang.org/x/tools/gopls@latest \
15+
&& go install github.com/go-delve/delve/cmd/dlv@latest
16+
17+
# Create non-root user
18+
ARG USERNAME=vscode
19+
ARG USER_UID=1000
20+
ARG USER_GID=$USER_UID
21+
22+
RUN groupadd --gid $USER_GID $USERNAME \
23+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
24+
&& apt-get update \
25+
&& apt-get install -y sudo \
26+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
27+
&& chmod 0440 /etc/sudoers.d/$USERNAME
28+
29+
# Set the default user
30+
USER $USERNAME
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "Go Development Container",
3+
"dockerFile": "Dockerfile",
4+
"runArgs": [
5+
"--cap-add=SYS_PTRACE",
6+
"--security-opt", "seccomp=unconfined"
7+
],
8+
"customizations": {
9+
"vscode": {
10+
"settings": {
11+
"go.toolsManagement.checkForUpdates": "local",
12+
"go.useLanguageServer": true,
13+
"go.gopath": "/go"
14+
},
15+
"extensions": [
16+
"golang.go",
17+
"ms-azuretools.vscode-docker"
18+
]
19+
}
20+
},
21+
"remoteUser": "vscode",
22+
"features": {
23+
"docker-in-docker": {
24+
"version": "latest",
25+
"moby": true
26+
}
27+
}
28+
}

docker/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Start from a Go base image
2+
FROM golang:1.21-alpine
3+
4+
# Set the working directory inside the container
5+
WORKDIR /app
6+
7+
# Copy go.mod and go.sum files
8+
COPY go.mod go.sum ./
9+
10+
# Download all dependencies
11+
RUN go mod download
12+
13+
# Copy the source code into the container
14+
COPY . .
15+
16+
# Build the application
17+
RUN go build -o /samples ./...
18+
19+
# Command to run when starting the container
20+
CMD ["/samples"]

docker/build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Default values
4+
DOCKER_REGISTRY=${DOCKER_REGISTRY:-"docker.io/your-username"}
5+
TAG=${TAG:-"latest"}
6+
7+
# Build the Docker image
8+
echo "Building Docker image..."
9+
docker build -t ${DOCKER_REGISTRY}/cadence-helloworld-worker:${TAG} -f docker/docker/Dockerfile .
10+
11+
# Push the image if requested
12+
if [ "$1" == "push" ]; then
13+
echo "Pushing Docker image to registry..."
14+
docker push ${DOCKER_REGISTRY}/cadence-helloworld-worker:${TAG}
15+
fi

docker/docker/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Build stage
2+
FROM golang:1.21-alpine AS builder
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Copy source code
8+
COPY hello-world/main.go .
9+
10+
# Build the binary
11+
RUN CGO_ENABLED=0 GOOS=linux go build -o /hello-world main.go
12+
13+
# Final stage
14+
FROM alpine:3.18
15+
16+
# Copy the binary from builder
17+
COPY --from=builder /hello-world /usr/local/bin/
18+
19+
# Set the binary as the entrypoint
20+
ENTRYPOINT ["hello-world"]
21+
22+
# Install necessary runtime dependencies
23+
RUN apk --no-cache add ca-certificates tzdata
24+
25+
# Copy the built executable
26+
COPY --from=builder /samples/hello-world /app/hello-world
27+
28+
# Set working directory
29+
WORKDIR /app
30+
31+
# Command to run the sample
32+
ENTRYPOINT ["/app/hello-world"]

docker/docker/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Dockerized Cadence Samples
2+
3+
## Overview
4+
This project adds Docker support to Cadence samples, making them easier to deploy in containerized environments like Kubernetes.
5+
6+
## Why Dockerize?
7+
- Enable easy deployment to cloud environments
8+
- Ensure consistent runtime environment
9+
- Simplify the getting started experience
10+
- Support Kubernetes deployment scenarios
11+
12+
## Directory Structure
13+
```
14+
samples/docker/
15+
├── Dockerfile # Main Dockerfile for samples
16+
├── docker-compose.yml # Local development setup
17+
└── k8s/ # Kubernetes deployment files
18+
```
19+
20+
## Getting Started
21+
1. Build the Docker image:
22+
```bash
23+
docker build -t cadence-samples .
24+
```
25+
26+
2. Run using Docker Compose:
27+
```bash
28+
docker-compose up
29+
```
30+
31+
## Testing
32+
- Unit tests: `make test`
33+
- Integration tests: `make integration-test`
34+
- Manual verification steps in [TESTING.md](TESTING.md)
35+
36+
## What's Next?
37+
- [ ] Add Kubernetes Helm charts
38+
- [ ] Add CI/CD pipeline for automated builds
39+
- [ ] Add more sample workflows

docker/docker/go.mod

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module github.com/uber/cadence/samples/hello-world
2+
3+
go 1.25.2
4+
5+
require (
6+
go.uber.org/cadence v1.3.0
7+
go.uber.org/zap v1.27.0
8+
)
9+
10+
require (
11+
github.com/BurntSushi/toml v0.4.1 // indirect
12+
github.com/apache/thrift v0.16.0 // indirect
13+
github.com/beorn7/perks v1.0.1 // indirect
14+
github.com/cespare/xxhash/v2 v2.1.1 // indirect
15+
github.com/davecgh/go-spew v1.1.1 // indirect
16+
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
17+
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
18+
github.com/golang/mock v1.5.0 // indirect
19+
github.com/golang/protobuf v1.5.3 // indirect
20+
github.com/jonboulle/clockwork v0.4.0 // indirect
21+
github.com/marusama/semaphore/v2 v2.5.0 // indirect
22+
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
23+
github.com/opentracing/opentracing-go v1.1.0 // indirect
24+
github.com/pborman/uuid v0.0.0-20160209185913-a97ce2ca70fa // indirect
25+
github.com/pmezard/go-difflib v1.0.0 // indirect
26+
github.com/prometheus/client_golang v1.11.1 // indirect
27+
github.com/prometheus/client_model v0.2.0 // indirect
28+
github.com/prometheus/common v0.26.0 // indirect
29+
github.com/prometheus/procfs v0.6.0 // indirect
30+
github.com/robfig/cron v1.2.0 // indirect
31+
github.com/stretchr/objx v0.5.2 // indirect
32+
github.com/stretchr/testify v1.9.0 // indirect
33+
github.com/uber-go/tally v3.3.15+incompatible // indirect
34+
github.com/uber/tchannel-go v1.32.1 // indirect
35+
go.uber.org/atomic v1.11.0 // indirect
36+
go.uber.org/multierr v1.10.0 // indirect
37+
go.uber.org/net/metrics v1.3.0 // indirect
38+
go.uber.org/thriftrw v1.25.0 // indirect
39+
go.uber.org/yarpc v1.55.0 // indirect
40+
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e // indirect
41+
golang.org/x/lint v0.0.0-20200130185559-910be7a94367 // indirect
42+
golang.org/x/mod v0.8.0 // indirect
43+
golang.org/x/net v0.19.0 // indirect
44+
golang.org/x/oauth2 v0.1.0 // indirect
45+
golang.org/x/sys v0.15.0 // indirect
46+
golang.org/x/text v0.14.0 // indirect
47+
golang.org/x/time v0.0.0-20170927054726-6dc17368e09b // indirect
48+
golang.org/x/tools v0.6.0 // indirect
49+
google.golang.org/appengine v1.6.7 // indirect
50+
google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce // indirect
51+
google.golang.org/grpc v1.28.0 // indirect
52+
google.golang.org/protobuf v1.31.0 // indirect
53+
gopkg.in/yaml.v3 v3.0.1 // indirect
54+
honnef.co/go/tools v0.3.2 // indirect
55+
)
56+
57+
replace github.com/uber/cadence => ../..

0 commit comments

Comments
 (0)