Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: automate docker build and push + fix broken examples #62

Merged
merged 14 commits into from
Jul 5, 2024
Merged
40 changes: 40 additions & 0 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Docker Publish

on:
push:
branches: [ main ]
tags:
- '*'

jobs:
docker_publish:
# run workflow only on numaproj/numaflow-rs repository
if: ${{ github.repository }} == "numaproj/numaflow-rs"
name: Build, Tag, and Push Image
runs-on: ubuntu-latest

strategy:
matrix:
dockerfile_paths: [
"examples/map-cat", "examples/map-tickgen-serde", "examples/mapt-event-time-filter",
"examples/reduce-counter", "examples/sideinput", "examples/sideinput/udf",
"examples/simple-source", "examples/sink-log", "examples/source-transformer-now"
]

steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Install protobuf compiler
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Quay.io registry
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.NUMAIO_USERNAME }}
password: ${{ secrets.NUMAIO_PASSWORD }}
- name: Build, tag, and push images
run: ./hack/update_examples.sh --build-push-example ${{ matrix.dockerfile_paths }}
2 changes: 1 addition & 1 deletion examples/map-cat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ path = "src/main.rs"
[dependencies]
tonic = "0.10.2"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
numaflow = { git = "https://github.com/numaproj/numaflow-rs.git", branch = "main" }
numaflow = { path = "../../" }
19 changes: 7 additions & 12 deletions examples/map-cat/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
FROM rust:1.75-bookworm as build
FROM rust:1.75-bookworm AS build

RUN apt-get update
RUN apt-get install protobuf-compiler -y

# create a new empty shell project
WORKDIR /examples

# copy your source tree
COPY src ./src

Comment on lines -9 to -10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might copy unwanted files, right?

Copy link
Member Author

@ayildirim21 ayildirim21 Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess rather than copy the entire root directory with COPY ./ ./, the only necessary things necessary to copy over would be src/, proto/, Cargo.toml, and build.rs? Is there anything else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for examples, we do not require proto, build.rs, etc., right?

COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
WORKDIR /numaflow-rs
COPY ./ ./
WORKDIR /numaflow-rs/examples/map-cat

# build for release
RUN cargo build --release

# our final base
FROM debian:bookworm
FROM debian:bookworm AS map-cat

# copy the build artifact from the build stage
COPY --from=build /examples/target/release/server .
COPY --from=build /numaflow-rs/examples/map-cat/target/release/server .

# set the startup command to run your binary
CMD ["./server"]
CMD ["./server"]
20 changes: 20 additions & 0 deletions examples/map-cat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
TAG ?= stable
PUSH ?= false
IMAGE_REGISTRY = quay.io/numaio/numaflow-rs/map-cat:${TAG}
DOCKER_FILE_PATH = examples/map-cat/Dockerfile

.PHONY: update
update:
cargo check
cargo update

.PHONY: image
image: update
cd ../../ && docker build \
-f ${DOCKER_FILE_PATH} \
-t ${IMAGE_REGISTRY} .
@if [ "$(PUSH)" = "true" ]; then docker push ${IMAGE_REGISTRY}; fi

.PHONY: clean
clean:
-rm -rf target
2 changes: 1 addition & 1 deletion examples/map-cat/manifests/simple-map-cat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
min: 1
udf:
container:
image: quay.io/numaio/numaflow-rs/map-cat:v1
image: quay.io/numaio/numaflow-rs/map-cat:stable
- name: out
sink:
# A simple log printing sink
Expand Down
2 changes: 1 addition & 1 deletion examples/map-cat/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use numaflow::map;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
map::Server::new(Cat).start().await
}

Expand Down
2 changes: 1 addition & 1 deletion examples/map-tickgen-serde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
serde = { version = "1.0.103", features = ["derive"] }
serde_json = "1.0.103"
chrono = "0.4.26"
numaflow = { git = "https://github.com/numaproj/numaflow-rs.git", branch = "main" }
numaflow = { path = "../../" }
17 changes: 6 additions & 11 deletions examples/map-tickgen-serde/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
FROM rust:1.75-bookworm as build
FROM rust:1.75-bookworm AS build

RUN apt-get update
RUN apt-get install protobuf-compiler -y

# create a new empty shell project
WORKDIR /examples

# copy your source tree
COPY src ./src

COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
WORKDIR /numaflow-rs
COPY ./ ./
WORKDIR /numaflow-rs/examples/map-tickgen-serde

# build for release
RUN cargo build --release

# our final base
FROM debian:bookworm
FROM debian:bookworm AS map-tickgen-serde

# copy the build artifact from the build stage
COPY --from=build /examples/target/release/server .
COPY --from=build /numaflow-rs/examples/map-tickgen-serde/target/release/server .

# set the startup command to run your binary
CMD ["./server"]
20 changes: 20 additions & 0 deletions examples/map-tickgen-serde/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
TAG ?= stable
PUSH ?= false
IMAGE_REGISTRY = quay.io/numaio/numaflow-rs/map-tickgen-serde:${TAG}
DOCKER_FILE_PATH = examples/map-tickgen-serde/Dockerfile

.PHONY: update
update:
cargo check
cargo update

.PHONY: image
image: update
cd ../../ && docker build \
-f ${DOCKER_FILE_PATH} \
-t ${IMAGE_REGISTRY} .
@if [ "$(PUSH)" = "true" ]; then docker push ${IMAGE_REGISTRY}; fi

.PHONY: clean
clean:
-rm -rf target
2 changes: 1 addition & 1 deletion examples/map-tickgen-serde/manifests/simple-map-udf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
min: 1
udf:
container:
image: quay.io/numaio/numaflow-rs/map-tickgen-serde:v1
image: quay.io/numaio/numaflow-rs/map-tickgen-serde:stable
- name: out
sink:
# A simple log printing sink
Expand Down
20 changes: 20 additions & 0 deletions examples/mapt-event-time-filter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM rust:1.75-bookworm AS build

RUN apt-get update
RUN apt-get install protobuf-compiler -y

WORKDIR /numaflow-rs
COPY ./ ./
WORKDIR /numaflow-rs/examples/mapt-event-time-filter

# build for release
RUN cargo build --release

# our final base
FROM debian:bookworm AS mapt-event-time-filter

# copy the build artifact from the build stage
COPY --from=build /numaflow-rs/examples/mapt-event-time-filter/target/release/server .

# set the startup command to run your binary
CMD ["./server"]
20 changes: 20 additions & 0 deletions examples/mapt-event-time-filter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
TAG ?= stable
PUSH ?= false
IMAGE_REGISTRY = quay.io/numaio/numaflow-rs/mapt-event-time-filter:${TAG}
DOCKER_FILE_PATH = examples/mapt-event-time-filter/Dockerfile

.PHONY: update
update:
cargo check
cargo update

.PHONY: image
image: update
cd ../../ && docker build \
-f ${DOCKER_FILE_PATH} \
-t ${IMAGE_REGISTRY} .
@if [ "$(PUSH)" = "true" ]; then docker push ${IMAGE_REGISTRY}; fi

.PHONY: clean
clean:
-rm -rf target
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
duration: 1s
transformer:
container:
image: quay.io/numaio/numaflow-rust/mapt-event-time-filter:stable
image: quay.io/numaio/numaflow-rs/mapt-event-time-filter:stable
imagePullPolicy: Always
- name: out
scale:
Expand Down
3 changes: 2 additions & 1 deletion examples/reduce-counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ path = "src/main.rs"
[dependencies]
tonic = "0.11.0"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
numaflow-rs = { path = "../../" }
numaflow = { path = "../../" }
KeranYang marked this conversation as resolved.
Show resolved Hide resolved

17 changes: 6 additions & 11 deletions examples/reduce-counter/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
FROM rust:1.70 as build
FROM rust:1.70 AS build

RUN apt-get update
RUN apt-get install protobuf-compiler -y

# create a new empty shell project
WORKDIR /examples

# copy your source tree
COPY src ./src

COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
WORKDIR /numaflow-rs
COPY ./ ./
WORKDIR /numaflow-rs/examples/reduce-counter

# build for release
RUN cargo build --release

# our final base
FROM rust
FROM rust AS reduce-counter

# copy the build artifact from the build stage
COPY --from=build /examples/target/release/server .
COPY --from=build /numaflow-rs/examples/reduce-counter/target/release/server .

# set the startup command to run your binary
CMD ["./server"]
20 changes: 20 additions & 0 deletions examples/reduce-counter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
TAG ?= stable
PUSH ?= false
IMAGE_REGISTRY = quay.io/numaio/numaflow-rs/reduce-counter:${TAG}
DOCKER_FILE_PATH = examples/reduce-counter/Dockerfile

.PHONY: update
update:
cargo check
cargo update

.PHONY: image
image: update
cd ../../ && docker build \
-f ${DOCKER_FILE_PATH} \
-t ${IMAGE_REGISTRY} .
@if [ "$(PUSH)" = "true" ]; then docker push ${IMAGE_REGISTRY}; fi

.PHONY: clean
clean:
-rm -rf target
2 changes: 1 addition & 1 deletion examples/reduce-counter/manifests/simple-reduce.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
udf:
container:
# count element
image: quay.io/numaio/numaflow-rs/reduce-counter:v1
image: quay.io/numaio/numaflow-rs/reduce-counter:stable
groupBy:
window:
fixed:
Expand Down
25 changes: 0 additions & 25 deletions examples/side-input/Dockerfile

This file was deleted.

13 changes: 0 additions & 13 deletions examples/side-input/Makefile

This file was deleted.

27 changes: 0 additions & 27 deletions examples/sideinput-udf/Dockerfile

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "side-input"
name = "sideinput"
version = "0.1.0"
edition = "2021"

Expand All @@ -11,5 +11,5 @@ path = "src/main.rs"
[dependencies]
tonic = "0.9"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
numaflow = { git = "https://github.com/numaproj/numaflow-rs.git", branch = "main" }
numaflow = { path = "../../" }
chrono = "0.4.30"
Loading
Loading