Skip to content

Commit

Permalink
Dockerize
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman committed Feb 12, 2024
1 parent bc5fa48 commit d80b9d9
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target/
.github/
deploy/
crd/
tests/
11 changes: 11 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Build docker image

on:
workflow_dispatch:
workflow_call:

jobs:
build-docker-image:
name: Build docker image
uses: restatedev/restate/.github/workflows/docker.yml@main
secrets: inherit
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Create new release

on:
push:
tags:
- v**

jobs:
build-docker-image:
name: Build release Docker image
uses: ./.github/workflows/docker.yml
secrets: inherit

publish-release:
name: Publish release
runs-on: ubuntu-latest
needs: [build-docker-image]

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create release
uses: softprops/action-gh-release@v1
with:
# create a draft release which needs manual approval
draft: true
files: |
crd/crd.yaml
deploy/operator.pkl
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM --platform=$BUILDPLATFORM ghcr.io/restatedev/dev-tools:latest AS planner
COPY . .
RUN just chef-prepare

FROM --platform=$BUILDPLATFORM ghcr.io/restatedev/dev-tools:latest AS base
COPY --from=planner /restate/recipe.json recipe.json
COPY justfile justfile

# avoid sharing sccache port between multiplatform builds - they share a network but not a filesystem, so it won't work
FROM base AS base-amd64
ARG SCCACHE_SERVER_PORT=4226

FROM base AS base-arm64
ARG SCCACHE_SERVER_PORT=4227

FROM base-$TARGETARCH AS builder
ARG SCCACHE_SERVER_PORT
ARG TARGETARCH
# https://github.com/mozilla/sccache/blob/main/docs/GHA.md
ARG ACTIONS_CACHE_URL=''
ARG ACTIONS_RUNTIME_TOKEN=''
ARG SCCACHE_GHA_ENABLED=''
# Overrides the behaviour of the release profile re including debug symbols, which in our repo is not to include them.
# Should be set to 'false' or 'true'. See https://doc.rust-lang.org/cargo/reference/environment-variables.html
ARG CARGO_PROFILE_RELEASE_DEBUG=false
RUN just arch=$TARGETARCH libc=musl chef-cook --release --bin restate-operator
COPY . .
RUN just arch=$TARGETARCH libc=musl build --release --bin restate-operator && mv target/$(just arch=$TARGETARCH libc=musl print-target)/release/restate-operator target/restate-operator

FROM gcr.io/distroless/static:nonroot
COPY --from=builder --chown=nonroot:nonroot /restate/target/restate-operator /app/restate-operator
ENTRYPOINT ["/app/restate-operator"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Restate Operator

## Releasing
1. Update the image version in deploy/operator.pkl and the version in Cargo.toml eg to `0.0.2`
2. Push a new tag `v0.0.2`
3. Accept the draft release once the workflow finishes
64 changes: 64 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
export DOCKER_PROGRESS := env_var_or_default('DOCKER_PROGRESS', 'auto')

features := ""
libc := "libc"
arch := "" # use the default architecture
os := "" # use the default os
image := "ghcr.io/restatedev/restate-operator:local"

_features := if features == "all" {
"--all-features"
} else if features != "" {
"--features=" + features
} else { "" }

_arch := if arch == "" {
arch()
} else if arch == "amd64" {
"x86_64"
} else if arch == "x86_64" {
"x86_64"
} else if arch == "arm64" {
"aarch64"
} else if arch == "aarch64" {
"aarch64"
} else {
error("unsupported arch=" + arch)
}

_os := if os == "" {
os()
} else {
os
}

_os_target := if _os == "macos" {
"apple-darwin"
} else if _os == "linux" {
"unknown-linux"
} else {
error("unsupported os=" + _os)
}

_default_target := `rustc -vV | sed -n 's|host: ||p'`
target := _arch + "-" + _os_target + if _os == "linux" { "-" + libc } else { "" }
_resolved_target := if target != _default_target { target } else { "" }
_target-option := if _resolved_target != "" { "--target " + _resolved_target } else { "" }

generate:
cargo run --bin crdgen > crd/crd.yaml

Expand All @@ -6,3 +53,20 @@ generate-pkl:

install-crd: generate
kubectl apply -f crd/crd.yaml

# Extract dependencies
chef-prepare:
cargo chef prepare --recipe-path recipe.json

# Compile dependencies
chef-cook *flags:
cargo chef cook --recipe-path recipe.json {{ _target-option }} {{ _features }} {{ flags }}

print-target:
@echo {{ _resolved_target }}

build *flags:
cargo build {{ _target-option }} {{ _features }} {{ flags }}

docker:
docker build . --tag={{ image }} --progress='{{ DOCKER_PROGRESS }}' --load

0 comments on commit d80b9d9

Please sign in to comment.