Skip to content

Commit

Permalink
chore!: switch from minikube to kind+tilt
Browse files Browse the repository at this point in the history
  • Loading branch information
bojidar-bg committed Oct 1, 2024
1 parent 9c33adb commit 666dc27
Show file tree
Hide file tree
Showing 32 changed files with 633 additions and 338 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ indent_size = 2
[*.{yml,yaml}]
indent_style = space
indent_size = 2

[Tiltfile]
indent_style = space
indent_size = 2
21 changes: 21 additions & 0 deletions .github/workflows/check-py.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check Python code

on:
push:
paths:
- '**/Tiltfile'
- '**.py'
- '.github/workflows/check-py.yml'

jobs:
check-fmt:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check format
uses: psf/black@stable
options: '--line-length 100 --include Tiltfile --check'
37 changes: 26 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,77 @@

## common: ##

FROM docker.io/library/golang@sha256:1a5326b07cbab12f4fd7800425f2cf25ff2bd62c404ef41b56cb99669a710a83 as build-common
FROM docker.io/library/golang:1.23.1-bullseye AS build-dependencies
#FROM docker.io/library/golang@sha256:1a5326b07cbab12f4fd7800425f2cf25ff2bd62c404ef41b56cb99669a710a83 AS build-dependencies
# 1.23.1-bookworm

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y protobuf-compiler libgpgme-dev && rm -rf /var/lib/apt/lists/*
RUN go install google.golang.org/protobuf/cmd/[email protected] && go install google.golang.org/grpc/cmd/[email protected] && go install github.com/ethereum/go-ethereum/cmd/[email protected]

FROM build-dependencies AS build-common

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download && go mod verify
RUN --mount=type=cache,target=/root/.cache/go-build go mod download && go mod verify

COPY pkg ./pkg

FROM docker.io/debian@sha256:a629e796d77a7b2ff82186ed15d01a493801c020eed5ce6adaa2704356f15a1c as run-common
#FROM docker.io/debian@sha256:a629e796d77a7b2ff82186ed15d01a493801c020eed5ce6adaa2704356f15a1c AS run-common
FROM docker.io/debian:bullseye-slim AS run-common
# bookworm-20240904-slim matching golang:1.23.1-bookworm

RUN apt-get update && apt-get install -y libgpgme11 curl jq && rm -rf /var/lib/apt/lists/*

## p2p-helper: ##

FROM build-common as build-p2p-helper
FROM build-common AS build-p2p-helper

COPY cmd/ipfs-p2p-helper ./cmd/ipfs-p2p-helper
RUN --mount=type=cache,target=/root/.cache/go-build go build -v -o /usr/local/bin/ipfs-p2p-helper ./cmd/ipfs-p2p-helper

FROM run-common as p2p-helper
FROM run-common AS p2p-helper

COPY --from=build-p2p-helper /usr/local/bin/ipfs-p2p-helper /usr/local/bin/ipfs-p2p-helper

ENTRYPOINT ["ipfs-p2p-helper"]

FROM run-common AS p2p-helper-copy-local

COPY ./bin/ipfs-p2p-helper /usr/local/bin/ipfs-p2p-helper

ENTRYPOINT ["ipfs-p2p-helper"]

## server: ##

FROM build-common as build-server
FROM build-common AS build-server

COPY cmd/tpodserver ./cmd/tpodserver
RUN --mount=type=cache,target=/root/.cache/go-build go build -v -o /usr/local/bin/tpodserver ./cmd/tpodserver
# RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=bind,source=.,target=/app go build -v -o /usr/local/bin/tpodserver ./cmd/tpodserver

FROM run-common as server
FROM run-common AS server

COPY --from=build-server /usr/local/bin/tpodserver /usr/local/bin/tpodserver

ENTRYPOINT ["tpodserver"]

FROM run-common AS server-copy-local

COPY ./bin/tpodserver /usr/local/bin/tpodserver

ENTRYPOINT ["tpodserver"]

## autoscaler: ##

FROM build-common as build-autoscaler
FROM build-common AS build-autoscaler

COPY autoscaler ./autoscaler
RUN --mount=type=cache,target=/root/.cache/go-build go build -v -o /usr/local/bin/autoscaler ./autoscaler

FROM run-common as autoscaler
FROM run-common AS autoscaler

COPY --from=build-autoscaler /usr/local/bin/autoscaler /usr/local/bin/autoscaler

ENTRYPOINT ["autoscaler"]


29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ Before running the various tests, Make sure the following dependencies are insta
- **[kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/)**: The Kubernetes command-line tool for managing Kubernetes clusters.
- **[docker](https://docs.docker.com/engine/install/)**: platform for developing, shipping, and running applications using containerization.
- **[jq](https://jqlang.github.io/jq/)**: lightweight and flexible command-line JSON processor.
- **[minikube](https://minikube.sigs.k8s.io/docs/start/)**: tool that runs a single-node Kubernetes cluster locally.
- **[kind](https://kind.sigs.k8s.io/docs/user/quick-start/)**: tool that runs a single-node Kubernetes cluster locally.
- **[ctlptl](https://github.com/tilt-dev/ctlptl/)**: An utility for declaratively setting up local Kubernetes clusters.
- **[tilt](https://docs.tilt.dev/install.html)**: A toolkit automating the process of setting up a new local development cluster.
- **[helm](https://helm.sh/)**: package manager for Kubernetes
- **[helmfile](https://github.com/helmfile/helmfile)**: declarative configuration tool for Helm.
- **[forge, cast, anvil](https://github.com/foundry-rs/foundry)**: tools for building Ethereum-based applications.
- **[forge, cast, anvil](https://github.com/foundry-rs/foundry)**: tools for building Ethereum-based applications. <!-- TODO: Move to container -->
- **[ipfs](https://docs.ipfs.tech/install/command-line/#install-official-binary-distributions)**: The InterPlanetary File System
- **[constellation](https://docs.edgeless.systems/constellation/getting-started/first-steps-local)**: Constellation is a Kubernetes engine that provides a secure and confidential way to run Kubernetes clusters. (Needed in `test/e2e/constellation`).

Expand All @@ -55,30 +57,35 @@ npm i && turbo sync
```
> Rerun `turbo sync` whenever you change files under the `proto/` and `contracts/` folders.
To start a local environment for e.g. integration-testing or evaluating the project, you can use the end-to-end tests in the `test/e2e` folder.
To start a local environment for e.g. integration-testing or evaluating the project, you can use `tilt` with Tiltfile in the `test/e2e` folder.

Typical development involves running the minikube end-to-end test, which can be done using the following command:
You can use it, for example, by running the following commands:

```bash
./test/e2e/minikube/run-test.sh
# Create a kind cluster:
ctlptl create cluster kind --registry=ctlptl-registry --kubernetes-version=v1.31.0
# Start tilt and run the nginx test:
tilt up -- --include ./test/e2e/nginx/Tiltfile
```

The command, after all dependencies are met, will proceed to start a local docker registry and test ethereum node, build and upload the project to them, then spin up a minikube cluster and deploy all necessary prerequisites into it, and finally deploying a pod from a [manifest file](spec/MANIFEST.md) into the cluster and then querying it over HTTP. It should display the curl command used to query the pod, and you should be able to use it yourself after the script is finished.
The first command will spin up a kind cluster with a local registry. Then, the second command will, after checking that any additional dependencies are met, then deploy all necessary prerequisites into local cluster, and finally deploying a pod from a [manifest file](spec/MANIFEST.md) into the cluster. <!-- TODO and then querying it over HTTP. It should display the curl command used to query the pod, and you should be able to use it yourself after the script is finished. -->

<!-- TODO
In addition, once you have started the minikube end-to-end test, you can also run the web UI test, which presents a sample interface that publishers can use to deploy a predefined pod template onto the minikube cluster / provider directly from their web browser.
```bash
turbo dev
```
``` -->

Once you are done playing around with the tests, simply run the following command to delete and stop the minikube cluster:
Once you are done playing around with the test, run the following commands to clean up:

```bash
test/e2e/minikube/run-test.sh teardown
# Clean up the local cluster:
tilt down -- --include ./test/e2e/nginx/Tiltfile
# Delete up the local cluster:
ctlptl create delete kind
```

(or alternatively, pass `teardown full` to also stop any local docker containers used by the test)

<!-- Note that while committing generated files is foreign to Nodejs/NPM, it's the usual way of life in the Go ecosystem, as packages are directly cloned from git rather than downloaded from the package manager. Here we are committing both in order to not require forge/protoc for JavaScript development when it's optional for Go development. -->

## Contributing
Expand Down
15 changes: 15 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- mode: Python -*-
# SPDX-License-Identifier: GPL-3.0

load(
"./deploy/Tiltfile", "apocryph_resource", "apocryph_build_with_builder", "deploy_apocryph_stack"
)

config.define_string_list("include")
cfg = config.parse()

apocryph_build_with_builder()
deploy_apocryph_stack()

for f in cfg["include"]:
load_dynamic(f)
25 changes: 25 additions & 0 deletions cmd/trustedpods/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/rand"
"fmt"
"math/big"
"os"
"path/filepath"

"github.com/comrade-coop/apocryph/pkg/abi"
Expand Down Expand Up @@ -270,6 +271,27 @@ var deletePodCmd = &cobra.Command{
},
}

var podNamespaceCmd = &cobra.Command{
Use: fmt.Sprintf("namespace [%s|deployment.yaml]", publisher.DefaultPodFile),
Short: "Get a pod's expected namespace in kubernetes",
Long: "Temporary command, may be removed once/if namespaces are implemented differently.",
GroupID: "lowlevel",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
_, _, _, deployment, err := publisher.ReadPodAndDeployment(args, manifestFormat, deploymentFormat)
if err != nil {
return err
}
configureDeployment(deployment)

ns := pbcon.NamespaceFromTokenParts(common.BytesToAddress(deployment.Payment.PublisherAddress), common.Hash(deployment.Payment.PodID))

_, err = fmt.Fprintln(os.Stdout, ns)

return err
},
}

func init() {
podCmd.AddCommand(deployPodCmd)
podCmd.AddCommand(deletePodCmd)
Expand All @@ -282,4 +304,7 @@ func init() {
deletePodCmd.Flags().AddFlagSet(deploymentFlags)
deletePodCmd.Flags().AddFlagSet(syncFlags)

podCmd.AddCommand(podNamespaceCmd)
podNamespaceCmd.Flags().AddFlagSet(deploymentFlags)
podNamespaceCmd.Flags().AddFlagSet(fundFlags)
}
5 changes: 4 additions & 1 deletion cmd/trustedpods/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ var _ = func() error {
fundFlags.Int64Var(&unlockTime, "unlock-time", 5*60, "time for unlocking tokens (in seconds)")

syncFlags.AddFlag(uploadFlags.Lookup("ipfs"))
syncFlags.StringVar(&publisherKey, "ethereum-key", "", "account string (private key | http[s]://clef#account | /keystore#account | account (in default keystore))")
syncFlags.AddFlag(fundFlags.Lookup("ethereum-key"))
syncFlags.AddFlag(fundFlags.Lookup("pod-id"))

registryFlags.StringVar(&ipfsApi, "ipfs", "/ip4/127.0.0.1/tcp/5001", "multiaddr where the ipfs/kubo api can be accessed")
registryFlags.StringVar(&registryContractAddress, "registry-contract", "", "registry contract address")
Expand All @@ -91,6 +92,8 @@ var _ = func() error {
registryFlags.StringVar(&tableId, "id", "", "table id")
registryFlags.StringVar(&region, "region", "", "filter providers by region, Ex: us-east-8")
registryFlags.AddFlag(fundFlags.Lookup("ethereum-key"))
registryFlags.AddFlag(fundFlags.Lookup("ethereum-rpc"))


return nil
}()
Expand Down
Loading

0 comments on commit 666dc27

Please sign in to comment.