Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2412 from ibuildthecloud/main
Browse files Browse the repository at this point in the history
Add local environment
  • Loading branch information
ibuildthecloud authored Jan 15, 2024
2 parents 10e6da7 + 91c21c7 commit 00d8740
Show file tree
Hide file tree
Showing 33 changed files with 1,821 additions and 27 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ dockers:
- scripts/setup-binfmt
- scripts/acorn-busybox-init
- scripts/40-copy-resolv-nameserver.sh
- scripts/k3s-config.yaml
- use: buildx
goos: linux
goarch: arm64
Expand Down
29 changes: 23 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# syntax=docker/dockerfile:1.3-labs

FROM ghcr.io/acorn-io/images-mirror/tonistiigi/binfmt:qemu-v6.2.0 AS binfmt
FROM ghcr.io/acorn-io/images-mirror/moby/buildkit:v0.11.6 AS buildkit
FROM ghcr.io/acorn-io/images-mirror/registry:2.8.1 AS registry
FROM ghcr.io/acorn-io/images-mirror/rancher/klipper-lb:v0.3.5 AS klipper-lb
FROM ghcr.io/acorn-io/images-mirror/tonistiigi/binfmt:qemu-v8.1.4 AS binfmt
FROM ghcr.io/acorn-io/images-mirror/coredns/coredns:1.10.1 AS coredns
FROM ghcr.io/acorn-io/images-mirror/moby/buildkit:v0.12.4 AS buildkit
FROM ghcr.io/acorn-io/images-mirror/registry:2.8.3 AS registry
FROM ghcr.io/acorn-io/images-mirror/traefik:2.10.7 AS traefik
FROM ghcr.io/acorn-io/images-mirror/rancher/k3s:v1.29.0-k3s1 AS k3s
FROM ghcr.io/acorn-io/images-mirror/rancher/klipper-lb:v0.4.5 AS klipper-lb
FROM ghcr.io/acorn-io/sleep:latest AS sleep

FROM ghcr.io/acorn-io/images-mirror/golang:1.21-alpine AS helper
Expand All @@ -12,6 +15,11 @@ RUN apk -U add curl
RUN curl -sfL https://github.com/loft-sh/devspace/archive/refs/tags/v6.3.2.tar.gz | tar xzf - --strip-components=1
RUN --mount=type=cache,target=/go/pkg --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 go build -o /usr/local/bin/acorn-helper -ldflags "-s -w" ./helper

FROM cgr.dev/chainguard/wolfi-base AS pause
RUN apk add -U crane
RUN crane pull --platform=linux/amd64 --platform=linux/arm64 --format=oci rancher/mirrored-pause:3.6 /out
RUN tar cvf /pause.tar -C /out .

FROM ghcr.io/acorn-io/images-mirror/golang:1.21-alpine AS loglevel
WORKDIR /usr/src
RUN apk -U add curl && rm -rf /var/cache/apk/*
Expand All @@ -28,27 +36,36 @@ FROM ghcr.io/acorn-io/images-mirror/nginx:1.23.2-alpine AS base
RUN apk add --no-cache ca-certificates iptables ip6tables fuse3 git openssh pigz xz busybox-static \
&& ln -s fusermount3 /usr/bin/fusermount
RUN adduser -D acorn
RUN mkdir apiserver.local.config && chown acorn apiserver.local.config
RUN mkdir /wd && \
chown acorn /wd && \
mkdir /etc/coredns
RUN --mount=from=binfmt,src=/usr/bin,target=/usr/src for i in aarch64 x86_64; do if [ -e /usr/src/qemu-$i ]; then cp /usr/src/qemu-$i /usr/bin; fi; done
RUN --mount=from=buildkit,src=/usr/bin,target=/usr/src for i in aarch64 x86_64; do if [ -e /usr/src/buildkit-qemu-$i ]; then cp /usr/src/buildkit-qemu-$i /usr/bin; fi; done
COPY --from=binfmt /usr/bin/binfmt /usr/local/bin
COPY --from=buildkit /usr/bin/buildkitd /usr/bin/buildctl /usr/bin/buildkit-runc /usr/local/bin/
COPY --from=registry /etc/docker/registry/config.yml /etc/docker/registry/config.yml
COPY --from=registry /bin/registry /usr/local/bin
COPY --from=klipper-lb /usr/bin/entry /usr/local/bin/klipper-lb
COPY --from=coredns /coredns /usr/local/bin/coredns
COPY --from=traefik /usr/local/bin/traefik /usr/local/bin/traefik
COPY --from=pause /pause.tar /var/lib/rancher/k3s/agent/images/
RUN --mount=from=k3s,target=/k3s tar cf - -C /k3s bin | tar xvf -
COPY ./scripts/ds-containerd-config-path-entry /usr/local/bin
COPY ./scripts/setup-binfmt /usr/local/bin
COPY ./scripts/40-copy-resolv-nameserver.sh /docker-entrypoint.d/
COPY --from=helper /usr/local/bin/acorn-helper /usr/local/bin/
COPY --from=loglevel /usr/local/bin/loglevel /usr/local/bin/
VOLUME /var/lib/buildkit

COPY /scripts/acorn-helper-init /usr/local/bin
COPY /scripts/acorn-busybox-init /usr/local/bin
COPY /scripts/acorn-job-helper-init /usr/local/bin
COPY /scripts/acorn-job-helper-shutdown /usr/local/bin
COPY /scripts/acorn-job-get-output /usr/local/bin
COPY /scripts/k3s-config.yaml /etc/rancher/k3s/config.yaml
CMD []
WORKDIR /wd
VOLUME /var/lib/buildkit
VOLUME /var/lib/rancher/k3s
STOPSIGNAL SIGTERM
ENTRYPOINT ["/usr/local/bin/acorn"]

Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/acorn-io/aml v0.0.0-20240106192317-21afc7320c77
github.com/acorn-io/aml/cli v0.0.0-20240106192317-21afc7320c77
github.com/acorn-io/baaah v0.0.0-20240105013849-c4f82d7a5a41
github.com/acorn-io/baaah v0.0.0-20240111044744-384c1595d964
github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d
github.com/acorn-io/function-builder v0.0.0-20240111042311-041315dd7091
github.com/acorn-io/mink v0.0.0-20240105015834-b1f7af4fadea
Expand All @@ -24,7 +24,9 @@ require (
github.com/denisbrodbeck/machineid v1.0.1
github.com/depot/depot-go v0.0.0-20230819013533-12cec5cbd2f9
github.com/docker/cli v24.0.0+incompatible
github.com/docker/docker v24.0.0+incompatible
github.com/docker/docker-credential-helpers v0.7.0
github.com/docker/go-connections v0.4.0
github.com/go-acme/lego/v4 v4.9.1
github.com/go-git/go-git/v5 v5.9.0
github.com/golang/mock v1.6.0
Expand Down Expand Up @@ -125,7 +127,7 @@ require (
github.com/digitorus/timestamp v0.0.0-20230821155606-d1ad5ca9624c // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.0+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ github.com/acorn-io/aml v0.0.0-20240106192317-21afc7320c77 h1:MFaoLSKZj1z9c+U7S0
github.com/acorn-io/aml v0.0.0-20240106192317-21afc7320c77/go.mod h1:z/Tz4f5dWHj/F5THru0+IQBIq31Xq06S5b7YpPkV7K0=
github.com/acorn-io/aml/cli v0.0.0-20240106192317-21afc7320c77 h1:KdXktTqCv1OlmkFYl7+P11Dh0NDiYnQFblNDdLXPhT4=
github.com/acorn-io/aml/cli v0.0.0-20240106192317-21afc7320c77/go.mod h1:tTw5qUW+S3cAoYepBLFdLNqaRV/DHV3YhHFhB2FzZhE=
github.com/acorn-io/baaah v0.0.0-20240105013849-c4f82d7a5a41 h1:ZzzhWJ2ZP1QQlibd9pll9UTfmitIGReW0x3VNNBg5Qw=
github.com/acorn-io/baaah v0.0.0-20240105013849-c4f82d7a5a41/go.mod h1:13nTO3svO8zTD3j9E5c86tCtK5YrKsK5sxca4Lwkbc0=
github.com/acorn-io/baaah v0.0.0-20240111044744-384c1595d964 h1:WmHOqQQbCrwNEPMXmbNj95lcUOK6s/yZqgSckPPDsvA=
github.com/acorn-io/baaah v0.0.0-20240111044744-384c1595d964/go.mod h1:13nTO3svO8zTD3j9E5c86tCtK5YrKsK5sxca4Lwkbc0=
github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d h1:hfpNQkJ4I2b8+DbMr8m97gG67ku0uPsMzUfskVu3cHU=
github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d/go.mod h1:WF6FYrEqW0+ZtY5OKb21JhSL0aeL5VJoVrm+u0d4gOE=
github.com/acorn-io/cmd v0.0.0-20230929053520-ebe1b9879b38 h1:oJMGvI702ZW5L0JjJfGV9ekzU2IqqTGjmAQl4gkO6Ro=
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/acorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func New() *cobra.Command {
NewVersion(cmdContext),
NewKubectl(cmdContext),
NewDashboard(cmdContext),
NewLocal(cmdContext),
)
// This will produce an error if the project flag doesn't exist or a completion function has already
// been registered for this flag. Not returning the error since neither of these is likely occur.
Expand Down
29 changes: 29 additions & 0 deletions pkg/cli/local.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cli

import (
cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/spf13/cobra"
)

func NewLocal(c CommandContext) *cobra.Command {
cmd := cli.Command(&Local{}, cobra.Command{
SilenceUsage: true,
Short: "Manage local development acorn runtime",
Hidden: true,
})
cmd.AddCommand(NewLocalServer(c))
cmd.AddCommand(NewLocalCreate(c))
cmd.AddCommand(NewLocalLogs(c))
cmd.AddCommand(NewLocalRm(c))
cmd.AddCommand(NewLocalStart(c))
cmd.AddCommand(NewLocalStop(c))
cmd.AddCommand(NewLocalReset(c))
return cmd
}

type Local struct {
}

func (a *Local) Run(cmd *cobra.Command, args []string) error {
return nil
}
35 changes: 35 additions & 0 deletions pkg/cli/local_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cli

import (
"fmt"

cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/acorn-io/runtime/pkg/local"
"github.com/acorn-io/runtime/pkg/system"
"github.com/spf13/cobra"
)

func NewLocalCreate(c CommandContext) *cobra.Command {
cmd := cli.Command(&Create{}, cobra.Command{
SilenceUsage: true,
Short: "Create local development server",
})
return cmd
}

type Create struct {
Upgrade bool `usage:"Upgrade if runtime already exists"`
}

func (a *Create) Run(cmd *cobra.Command, args []string) error {
c, err := local.NewContainer(cmd.Context())
if err != nil {
return err
}

if _, err := c.Create(cmd.Context(), a.Upgrade); err != nil {
return err
}
fmt.Println("running", system.DefaultImage())
return nil
}
30 changes: 30 additions & 0 deletions pkg/cli/local_logs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cli

import (
cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/acorn-io/runtime/pkg/local"
"github.com/spf13/cobra"
)

func NewLocalLogs(c CommandContext) *cobra.Command {
cmd := cli.Command(&LocalLogs{}, cobra.Command{
Use: "logs [flags]",
Aliases: []string{"log"},
SilenceUsage: true,
Short: "Show logs of local development server",
})
return cmd
}

type LocalLogs struct {
local.LogOptions
}

func (a *LocalLogs) Run(cmd *cobra.Command, args []string) error {
c, err := local.NewContainer(cmd.Context())
if err != nil {
return err
}

return c.Logs(cmd.Context(), a.LogOptions)
}
34 changes: 34 additions & 0 deletions pkg/cli/local_reset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cli

import (
"fmt"

cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/acorn-io/runtime/pkg/local"
"github.com/acorn-io/runtime/pkg/system"
"github.com/spf13/cobra"
)

func NewLocalReset(c CommandContext) *cobra.Command {
cmd := cli.Command(&Reset{}, cobra.Command{
SilenceUsage: true,
Short: "Reset local development server, deleting all data",
})
return cmd
}

type Reset struct {
}

func (a *Reset) Run(cmd *cobra.Command, args []string) error {
c, err := local.NewContainer(cmd.Context())
if err != nil {
return err
}

if err := c.Reset(cmd.Context()); err != nil {
return err
}
fmt.Println("running", system.DefaultImage())
return nil
}
36 changes: 36 additions & 0 deletions pkg/cli/local_rm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cli

import (
"fmt"

cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/acorn-io/runtime/pkg/local"
"github.com/spf13/cobra"
)

func NewLocalRm(c CommandContext) *cobra.Command {
cmd := cli.Command(&LocalRm{}, cobra.Command{
Use: "rm [flags]",
Aliases: []string{"delete"},
SilenceUsage: true,
Short: "Delete local development server",
})
return cmd
}

type LocalRm struct {
State bool `usage:"Include associated state (acorns and acorn data)"`
}

func (a *LocalRm) Run(cmd *cobra.Command, args []string) error {
c, err := local.NewContainer(cmd.Context())
if err != nil {
return err
}

if err := c.Delete(cmd.Context(), a.State); err != nil {
return err
}
fmt.Println("removed")
return nil
}
22 changes: 22 additions & 0 deletions pkg/cli/local_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cli

import (
cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/acorn-io/runtime/pkg/local"
"github.com/spf13/cobra"
)

func NewLocalServer(c CommandContext) *cobra.Command {
cmd := cli.Command(&Server{}, cobra.Command{
SilenceUsage: true,
Short: "Run local development server",
})
return cmd
}

type Server struct {
}

func (a *Server) Run(cmd *cobra.Command, args []string) error {
return local.ServerRun(cmd.Context())
}
40 changes: 40 additions & 0 deletions pkg/cli/local_start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cli

import (
"fmt"

cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/acorn-io/runtime/pkg/local"
"github.com/spf13/cobra"
)

func NewLocalStart(c CommandContext) *cobra.Command {
cmd := cli.Command(&LocalStart{}, cobra.Command{
Use: "start [flags]",
Aliases: []string{"delete"},
SilenceUsage: true,
Short: "Start local development server",
})
return cmd
}

type LocalStart struct {
}

func (a *LocalStart) Run(cmd *cobra.Command, args []string) error {
c, err := local.NewContainer(cmd.Context())
if err != nil {
return err
}

if _, err := c.Create(cmd.Context(), false); err != nil {
return err
}

if err := c.Start(cmd.Context()); err != nil {
return err
}

fmt.Println("started")
return nil
}
35 changes: 35 additions & 0 deletions pkg/cli/local_stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cli

import (
"fmt"

cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/acorn-io/runtime/pkg/local"
"github.com/spf13/cobra"
)

func NewLocalStop(c CommandContext) *cobra.Command {
cmd := cli.Command(&LocalStop{}, cobra.Command{
Use: "stop [flags]",
Aliases: []string{"delete"},
SilenceUsage: true,
Short: "Stop local development server",
})
return cmd
}

type LocalStop struct {
}

func (a *LocalStop) Run(cmd *cobra.Command, args []string) error {
c, err := local.NewContainer(cmd.Context())
if err != nil {
return err
}

if err := c.Stop(cmd.Context()); err != nil {
return err
}
fmt.Println("stopped")
return nil
}
Loading

0 comments on commit 00d8740

Please sign in to comment.