Skip to content

Commit

Permalink
Build and Push Sandbox Docker Image (flyteorg#735)
Browse files Browse the repository at this point in the history
* sandbox image

* wip

* wip

* wip

* first run experience

* flyte-sandbox Dockerfile (flyteorg#754)

* flyte-sandbox Dockerfile

* cleanup

* cleanup

* fix tags

* test changes to github action workflow

* wip

* wip

* test

* test

* fix

* test

* fix

* Move dockerfile

* update github workflows

* increase timeout for flyte deployment

* tweak timeouts and print error messages

* fix

* wait for flyte namespce before watching flyte deployments

* remove timeout for kubernetes cluster in wait-for-flyte.sh

* Update docker/sandbox/flyte-entrypoint-default.sh

* Update docker/sandbox/flyte-entrypoint-dind.sh

* Update docker/sandbox/wait-for-flyte.sh

* Update docker/sandbox/wait-for-flyte.sh

* Update docker/sandbox/wait-for-flyte.sh

Co-authored-by: Jeev B <[email protected]>
  • Loading branch information
EngHabu and jeevb authored Feb 22, 2021
1 parent a5e524e commit 9ea87b4
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/sandbox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build & Push Sandbox Docker Image

on:
pull_request:
release:
types: [published]

jobs:
push-sandbox-image:
name: Push sandbox image to GHCR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: "0"
- name: Push Sandbox Docker Image to Github Registry
uses: whoan/docker-build-with-cache-action@v5
with:
# https://docs.github.com/en/packages/learn-github-packages/publishing-a-package
username: "${{ secrets.FLYTE_BOT_USERNAME }}"
password: "${{ secrets.FLYTE_BOT_PAT }}"
image_name: ${{ github.repository_owner }}/flyte-sandbox
image_tag: latest,${{ github.sha }},${{ github.event.ref }}
registry: ghcr.io
build_extra_args: "--target=default --compress=true"
context: ./
dockerfile: docker/sandbox/Dockerfile
push_image_and_stages: ${{ github.event.name == 'release' }}
push-sandbox-dind-image:
name: Push sandbox DinD image to GHCR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: "0"
- name: Push Sandbox DinD Docker Image to Github Registry
uses: whoan/docker-build-with-cache-action@v5
with:
username: "${{ secrets.FLYTE_BOT_USERNAME }}"
password: "${{ secrets.FLYTE_BOT_PAT }}"
image_name: ${{ github.repository_owner }}/flyte-sandbox
image_tag: dind,dind-${{ github.sha }},dind-${{ github.event.ref }}
registry: ghcr.io
build_extra_args: "--target=dind --compress=true"
context: ./
dockerfile: docker/sandbox/Dockerfile
push_image_and_stages: ${{ github.event.name == 'release' }}
81 changes: 81 additions & 0 deletions docker/sandbox/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
FROM golang:1.16.0-alpine3.13 AS go_builder_

# Install dependencies
RUN apk add --no-cache build-base git make

# Create directory to store built artifacts
ARG INSTALL_DIR="/install"
RUN mkdir -p ${INSTALL_DIR}

ARG BUILDKIT_CLI_FOR_KUBECTL_VERSION="v0.1.2"
RUN git clone -b ${BUILDKIT_CLI_FOR_KUBECTL_VERSION} --single-branch --depth 1 https://github.com/vmware-tanzu/buildkit-cli-for-kubectl.git ${GOPATH}/src/github.com/vmware-tanzu/buildkit-cli-for-kubectl \
&& make -C ${GOPATH}/src/github.com/vmware-tanzu/buildkit-cli-for-kubectl ${INSTALL_DIR}/linux/kubectl-build BIN_DIR=${INSTALL_DIR} VERSION=${BUILDKIT_CLI_FOR_KUBECTL_VERSION}


FROM alpine:3.13.2 AS base_

# Make directory to store artifacts
RUN mkdir -p /flyteorg/bin /flyteorg/share

# Install k3s
ARG K3S_VERSION="v1.20.2%2Bk3s1"
RUN wget -q -O /flyteorg/bin/k3s https://github.com/k3s-io/k3s/releases/download/${K3S_VERSION}/k3s \
&& chmod +x /flyteorg/bin/k3s

# Install buildkit-cli-for-kubectl
COPY --from=go_builder_ /install/linux/ /flyteorg/bin/

# Download flyte manifest
COPY deployment/sandbox/flyte_generated.yaml /flyteorg/share/flyte_generated.yaml

# Copy scripts
COPY docker/sandbox/kubectl docker/sandbox/wait-for-flyte.sh /flyteorg/bin/


FROM base_ AS default

# Install dependencies
RUN apk add --no-cache tini

# Copy entrypoints
COPY docker/sandbox/flyte-entrypoint-default.sh /flyteorg/bin/flyte-entrypoint.sh

# Update PATH variable
ENV PATH "/flyteorg/bin:${PATH}"

# Declare volumes for k3s
VOLUME /var/lib/kubelet
VOLUME /var/lib/rancher/k3s
VOLUME /var/lib/cni
VOLUME /var/log

# Expose Flyte ports
EXPOSE 30081 30084

ENTRYPOINT ["tini", "flyte-entrypoint.sh"]


FROM docker:20.10.3-dind AS dind

# Install dependencies
RUN apk add --no-cache tini

# Copy artifacts from base
COPY --from=base_ /flyteorg/ /flyteorg/

# Copy entrypoints
COPY docker/sandbox/flyte-entrypoint-dind.sh /flyteorg/bin/flyte-entrypoint.sh

# Update PATH variable
ENV PATH "/flyteorg/bin:${PATH}"

# Declare volumes for k3s
VOLUME /var/lib/kubelet
VOLUME /var/lib/rancher/k3s
VOLUME /var/lib/cni
VOLUME /var/log

# Expose Flyte ports
EXPOSE 30081 30084

ENTRYPOINT ["tini", "flyte-entrypoint.sh"]
19 changes: 19 additions & 0 deletions docker/sandbox/flyte-entrypoint-default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

set -e

trap 'pkill -P $$' EXIT

# Start k3s
echo "Starting k3s cluster..."
k3s server --no-deploy=traefik --no-deploy=servicelb --no-deploy=local-storage --no-deploy=metrics-server &> /var/log/k3s.log &
K3S_PID=$!
timeout 600 sh -c "until k3s kubectl explain deployment &> /dev/null; do sleep 1; done" || ( echo >&2 "Timed out while waiting for the Kubernetes cluster to start"; exit 1 )
echo "Done."

# Deploy flyte
echo "Deploying Flyte..."
k3s kubectl apply -f /flyteorg/share/flyte_generated.yaml
wait-for-flyte.sh

wait ${K3S_PID}
37 changes: 37 additions & 0 deletions docker/sandbox/flyte-entrypoint-dind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

set -e

trap 'pkill -P $$' EXIT

monitor() {
while : ; do
for pid in $@ ; do
kill -0 $pid &> /dev/null || exit 1
done

sleep 1
done
}

# Start docker daemon
echo "Starting Docker daemon..."
dockerd &> /var/log/dockerd.log &
DOCKERD_PID=$!
timeout 600 sh -c "until docker info &> /dev/null; do sleep 1; done" || ( echo >&2 "Timed out while waiting for dockerd to start"; exit 1 )
echo "Done."

# Start k3s
echo "Starting k3s cluster..."
k3s server --docker --no-deploy=traefik --no-deploy=servicelb --no-deploy=local-storage --no-deploy=metrics-server &> /var/log/k3s.log &
K3S_PID=$!
timeout 600 sh -c "until k3s kubectl explain deployment &> /dev/null; do sleep 1; done" || ( echo >&2 "Timed out while waiting for the Kubernetes cluster to start"; exit 1 )
echo "Done."

# Deploy flyte
echo "Deploying Flyte..."
k3s kubectl apply -f /flyteorg/share/flyte_generated.yaml
wait-for-flyte.sh

# Monitor running processes. Exit when the first process exits.
monitor ${DOCKERD_PID} ${K3S_PID}
3 changes: 3 additions & 0 deletions docker/sandbox/kubectl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

exec k3s kubectl "$@"
21 changes: 21 additions & 0 deletions docker/sandbox/wait-for-flyte.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

set -e

echo "Waiting for Flyte to become ready..."

# Ensure cluster is up and running. We don't need a timeout here, since the container
# itself will exit with the appropriate error message if the kubernetes cluster is not
# up within the specified timeout.
until k3s kubectl explain deployment &> /dev/null; do sleep 1; done

# Wait for Flyte namespace to be created. This is necessary for the next step.
timeout 600 sh -c "until k3s kubectl get namespace flyte &> /dev/null; do sleep 1; done" || ( echo >&2 "Timed out while waiting for the Flyte namespace to be created"; exit 1 )

# Wait for flyte deployment
k3s kubectl wait --for=condition=available deployment/datacatalog deployment/flyteadmin deployment/flyteconsole deployment/flytepropeller -n flyte --timeout=10m || ( echo >&2 "Timed out while waiting for the Flyte deployment to start"; exit 1 )

# Wait for envoy proxy to become ready
timeout 600 sh -c 'until [[ $(k3s kubectl get daemonset envoy -n flyte -o jsonpath="{.status.numberReady}") -eq 1 ]]; do sleep 1; done' || ( echo >&2 "Timed out while waiting for the Flyte envoy proxy to start"; exit 1 )

echo "Flyte is ready! Flyte UI is available at http://localhost:30081/console."
1 change: 1 addition & 0 deletions rsts/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Welcome to the documentation hub for Flyte.
:caption: Get started with Flyte
:name: tutorialstoc

tutorials/first_run
tutorials/first_example
tutorials/run_on_flyte
tutorials/learn
Expand Down
21 changes: 21 additions & 0 deletions rsts/tutorials/first_run.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. _flyte-tutorials-firstrun:
.. currentmodule:: firstrun

############################################
Getting Started with Flyte
############################################

.. rubric:: Estimated time to complete: 2 minutes.

Flyte enables scalable, reproducable and reliable orchestration of massively large workflows. In order to get a sense of the product, we have packaged a minimalist version of the Flyte system into a Docker image.

With `docker installed <https://docs.docker.com/get-docker/>`__, run this command: ::

docker network create flyte-sandbox | docker run --network flyte-sandbox --rm --privileged -p 30081:30081 ghcr.io/flyteorg/flyte-sandbox

Once the container is ready, it'll output the Console URL. Go ahead and visit that to check out the Flyte UI.

A quick visual tour for launching your first Workflow:

.. image:: https://github.com/flyteorg/flyte/raw/static-resources/img/first-run-console-2.gif
:alt: A quick visual tour for launching your first Workflow.

0 comments on commit 9ea87b4

Please sign in to comment.