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

Commit 00d8740

Browse files
Merge pull request #2412 from ibuildthecloud/main
Add local environment
2 parents 10e6da7 + 91c21c7 commit 00d8740

33 files changed

+1821
-27
lines changed

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ dockers:
126126
- scripts/setup-binfmt
127127
- scripts/acorn-busybox-init
128128
- scripts/40-copy-resolv-nameserver.sh
129+
- scripts/k3s-config.yaml
129130
- use: buildx
130131
goos: linux
131132
goarch: arm64

Dockerfile

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# syntax=docker/dockerfile:1.3-labs
22

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

912
FROM ghcr.io/acorn-io/images-mirror/golang:1.21-alpine AS helper
@@ -12,6 +15,11 @@ RUN apk -U add curl
1215
RUN curl -sfL https://github.com/loft-sh/devspace/archive/refs/tags/v6.3.2.tar.gz | tar xzf - --strip-components=1
1316
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
1417

18+
FROM cgr.dev/chainguard/wolfi-base AS pause
19+
RUN apk add -U crane
20+
RUN crane pull --platform=linux/amd64 --platform=linux/arm64 --format=oci rancher/mirrored-pause:3.6 /out
21+
RUN tar cvf /pause.tar -C /out .
22+
1523
FROM ghcr.io/acorn-io/images-mirror/golang:1.21-alpine AS loglevel
1624
WORKDIR /usr/src
1725
RUN apk -U add curl && rm -rf /var/cache/apk/*
@@ -28,27 +36,36 @@ FROM ghcr.io/acorn-io/images-mirror/nginx:1.23.2-alpine AS base
2836
RUN apk add --no-cache ca-certificates iptables ip6tables fuse3 git openssh pigz xz busybox-static \
2937
&& ln -s fusermount3 /usr/bin/fusermount
3038
RUN adduser -D acorn
31-
RUN mkdir apiserver.local.config && chown acorn apiserver.local.config
39+
RUN mkdir /wd && \
40+
chown acorn /wd && \
41+
mkdir /etc/coredns
3242
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
3343
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
3444
COPY --from=binfmt /usr/bin/binfmt /usr/local/bin
3545
COPY --from=buildkit /usr/bin/buildkitd /usr/bin/buildctl /usr/bin/buildkit-runc /usr/local/bin/
3646
COPY --from=registry /etc/docker/registry/config.yml /etc/docker/registry/config.yml
3747
COPY --from=registry /bin/registry /usr/local/bin
3848
COPY --from=klipper-lb /usr/bin/entry /usr/local/bin/klipper-lb
49+
COPY --from=coredns /coredns /usr/local/bin/coredns
50+
COPY --from=traefik /usr/local/bin/traefik /usr/local/bin/traefik
51+
COPY --from=pause /pause.tar /var/lib/rancher/k3s/agent/images/
52+
RUN --mount=from=k3s,target=/k3s tar cf - -C /k3s bin | tar xvf -
3953
COPY ./scripts/ds-containerd-config-path-entry /usr/local/bin
4054
COPY ./scripts/setup-binfmt /usr/local/bin
4155
COPY ./scripts/40-copy-resolv-nameserver.sh /docker-entrypoint.d/
4256
COPY --from=helper /usr/local/bin/acorn-helper /usr/local/bin/
4357
COPY --from=loglevel /usr/local/bin/loglevel /usr/local/bin/
44-
VOLUME /var/lib/buildkit
4558

4659
COPY /scripts/acorn-helper-init /usr/local/bin
4760
COPY /scripts/acorn-busybox-init /usr/local/bin
4861
COPY /scripts/acorn-job-helper-init /usr/local/bin
4962
COPY /scripts/acorn-job-helper-shutdown /usr/local/bin
5063
COPY /scripts/acorn-job-get-output /usr/local/bin
64+
COPY /scripts/k3s-config.yaml /etc/rancher/k3s/config.yaml
5165
CMD []
66+
WORKDIR /wd
67+
VOLUME /var/lib/buildkit
68+
VOLUME /var/lib/rancher/k3s
5269
STOPSIGNAL SIGTERM
5370
ENTRYPOINT ["/usr/local/bin/acorn"]
5471

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/AlecAivazis/survey/v2 v2.3.6
88
github.com/acorn-io/aml v0.0.0-20240106192317-21afc7320c77
99
github.com/acorn-io/aml/cli v0.0.0-20240106192317-21afc7320c77
10-
github.com/acorn-io/baaah v0.0.0-20240105013849-c4f82d7a5a41
10+
github.com/acorn-io/baaah v0.0.0-20240111044744-384c1595d964
1111
github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d
1212
github.com/acorn-io/function-builder v0.0.0-20240111042311-041315dd7091
1313
github.com/acorn-io/mink v0.0.0-20240105015834-b1f7af4fadea
@@ -24,7 +24,9 @@ require (
2424
github.com/denisbrodbeck/machineid v1.0.1
2525
github.com/depot/depot-go v0.0.0-20230819013533-12cec5cbd2f9
2626
github.com/docker/cli v24.0.0+incompatible
27+
github.com/docker/docker v24.0.0+incompatible
2728
github.com/docker/docker-credential-helpers v0.7.0
29+
github.com/docker/go-connections v0.4.0
2830
github.com/go-acme/lego/v4 v4.9.1
2931
github.com/go-git/go-git/v5 v5.9.0
3032
github.com/golang/mock v1.6.0
@@ -125,7 +127,7 @@ require (
125127
github.com/digitorus/timestamp v0.0.0-20230821155606-d1ad5ca9624c // indirect
126128
github.com/dlclark/regexp2 v1.4.0 // indirect
127129
github.com/docker/distribution v2.8.2+incompatible // indirect
128-
github.com/docker/docker v24.0.0+incompatible // indirect
130+
github.com/docker/go-units v0.5.0 // indirect
129131
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
130132
github.com/emirpasic/gods v1.18.1 // indirect
131133
github.com/evanphx/json-patch v5.7.0+incompatible // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ github.com/acorn-io/aml v0.0.0-20240106192317-21afc7320c77 h1:MFaoLSKZj1z9c+U7S0
111111
github.com/acorn-io/aml v0.0.0-20240106192317-21afc7320c77/go.mod h1:z/Tz4f5dWHj/F5THru0+IQBIq31Xq06S5b7YpPkV7K0=
112112
github.com/acorn-io/aml/cli v0.0.0-20240106192317-21afc7320c77 h1:KdXktTqCv1OlmkFYl7+P11Dh0NDiYnQFblNDdLXPhT4=
113113
github.com/acorn-io/aml/cli v0.0.0-20240106192317-21afc7320c77/go.mod h1:tTw5qUW+S3cAoYepBLFdLNqaRV/DHV3YhHFhB2FzZhE=
114-
github.com/acorn-io/baaah v0.0.0-20240105013849-c4f82d7a5a41 h1:ZzzhWJ2ZP1QQlibd9pll9UTfmitIGReW0x3VNNBg5Qw=
115-
github.com/acorn-io/baaah v0.0.0-20240105013849-c4f82d7a5a41/go.mod h1:13nTO3svO8zTD3j9E5c86tCtK5YrKsK5sxca4Lwkbc0=
114+
github.com/acorn-io/baaah v0.0.0-20240111044744-384c1595d964 h1:WmHOqQQbCrwNEPMXmbNj95lcUOK6s/yZqgSckPPDsvA=
115+
github.com/acorn-io/baaah v0.0.0-20240111044744-384c1595d964/go.mod h1:13nTO3svO8zTD3j9E5c86tCtK5YrKsK5sxca4Lwkbc0=
116116
github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d h1:hfpNQkJ4I2b8+DbMr8m97gG67ku0uPsMzUfskVu3cHU=
117117
github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d/go.mod h1:WF6FYrEqW0+ZtY5OKb21JhSL0aeL5VJoVrm+u0d4gOE=
118118
github.com/acorn-io/cmd v0.0.0-20230929053520-ebe1b9879b38 h1:oJMGvI702ZW5L0JjJfGV9ekzU2IqqTGjmAQl4gkO6Ro=

pkg/cli/acorn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func New() *cobra.Command {
7474
NewVersion(cmdContext),
7575
NewKubectl(cmdContext),
7676
NewDashboard(cmdContext),
77+
NewLocal(cmdContext),
7778
)
7879
// This will produce an error if the project flag doesn't exist or a completion function has already
7980
// been registered for this flag. Not returning the error since neither of these is likely occur.

pkg/cli/local.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cli
2+
3+
import (
4+
cli "github.com/acorn-io/runtime/pkg/cli/builder"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
func NewLocal(c CommandContext) *cobra.Command {
9+
cmd := cli.Command(&Local{}, cobra.Command{
10+
SilenceUsage: true,
11+
Short: "Manage local development acorn runtime",
12+
Hidden: true,
13+
})
14+
cmd.AddCommand(NewLocalServer(c))
15+
cmd.AddCommand(NewLocalCreate(c))
16+
cmd.AddCommand(NewLocalLogs(c))
17+
cmd.AddCommand(NewLocalRm(c))
18+
cmd.AddCommand(NewLocalStart(c))
19+
cmd.AddCommand(NewLocalStop(c))
20+
cmd.AddCommand(NewLocalReset(c))
21+
return cmd
22+
}
23+
24+
type Local struct {
25+
}
26+
27+
func (a *Local) Run(cmd *cobra.Command, args []string) error {
28+
return nil
29+
}

pkg/cli/local_create.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
cli "github.com/acorn-io/runtime/pkg/cli/builder"
7+
"github.com/acorn-io/runtime/pkg/local"
8+
"github.com/acorn-io/runtime/pkg/system"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
func NewLocalCreate(c CommandContext) *cobra.Command {
13+
cmd := cli.Command(&Create{}, cobra.Command{
14+
SilenceUsage: true,
15+
Short: "Create local development server",
16+
})
17+
return cmd
18+
}
19+
20+
type Create struct {
21+
Upgrade bool `usage:"Upgrade if runtime already exists"`
22+
}
23+
24+
func (a *Create) Run(cmd *cobra.Command, args []string) error {
25+
c, err := local.NewContainer(cmd.Context())
26+
if err != nil {
27+
return err
28+
}
29+
30+
if _, err := c.Create(cmd.Context(), a.Upgrade); err != nil {
31+
return err
32+
}
33+
fmt.Println("running", system.DefaultImage())
34+
return nil
35+
}

pkg/cli/local_logs.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cli
2+
3+
import (
4+
cli "github.com/acorn-io/runtime/pkg/cli/builder"
5+
"github.com/acorn-io/runtime/pkg/local"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func NewLocalLogs(c CommandContext) *cobra.Command {
10+
cmd := cli.Command(&LocalLogs{}, cobra.Command{
11+
Use: "logs [flags]",
12+
Aliases: []string{"log"},
13+
SilenceUsage: true,
14+
Short: "Show logs of local development server",
15+
})
16+
return cmd
17+
}
18+
19+
type LocalLogs struct {
20+
local.LogOptions
21+
}
22+
23+
func (a *LocalLogs) Run(cmd *cobra.Command, args []string) error {
24+
c, err := local.NewContainer(cmd.Context())
25+
if err != nil {
26+
return err
27+
}
28+
29+
return c.Logs(cmd.Context(), a.LogOptions)
30+
}

pkg/cli/local_reset.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
cli "github.com/acorn-io/runtime/pkg/cli/builder"
7+
"github.com/acorn-io/runtime/pkg/local"
8+
"github.com/acorn-io/runtime/pkg/system"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
func NewLocalReset(c CommandContext) *cobra.Command {
13+
cmd := cli.Command(&Reset{}, cobra.Command{
14+
SilenceUsage: true,
15+
Short: "Reset local development server, deleting all data",
16+
})
17+
return cmd
18+
}
19+
20+
type Reset struct {
21+
}
22+
23+
func (a *Reset) Run(cmd *cobra.Command, args []string) error {
24+
c, err := local.NewContainer(cmd.Context())
25+
if err != nil {
26+
return err
27+
}
28+
29+
if err := c.Reset(cmd.Context()); err != nil {
30+
return err
31+
}
32+
fmt.Println("running", system.DefaultImage())
33+
return nil
34+
}

pkg/cli/local_rm.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
cli "github.com/acorn-io/runtime/pkg/cli/builder"
7+
"github.com/acorn-io/runtime/pkg/local"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
func NewLocalRm(c CommandContext) *cobra.Command {
12+
cmd := cli.Command(&LocalRm{}, cobra.Command{
13+
Use: "rm [flags]",
14+
Aliases: []string{"delete"},
15+
SilenceUsage: true,
16+
Short: "Delete local development server",
17+
})
18+
return cmd
19+
}
20+
21+
type LocalRm struct {
22+
State bool `usage:"Include associated state (acorns and acorn data)"`
23+
}
24+
25+
func (a *LocalRm) Run(cmd *cobra.Command, args []string) error {
26+
c, err := local.NewContainer(cmd.Context())
27+
if err != nil {
28+
return err
29+
}
30+
31+
if err := c.Delete(cmd.Context(), a.State); err != nil {
32+
return err
33+
}
34+
fmt.Println("removed")
35+
return nil
36+
}

pkg/cli/local_server.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cli
2+
3+
import (
4+
cli "github.com/acorn-io/runtime/pkg/cli/builder"
5+
"github.com/acorn-io/runtime/pkg/local"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func NewLocalServer(c CommandContext) *cobra.Command {
10+
cmd := cli.Command(&Server{}, cobra.Command{
11+
SilenceUsage: true,
12+
Short: "Run local development server",
13+
})
14+
return cmd
15+
}
16+
17+
type Server struct {
18+
}
19+
20+
func (a *Server) Run(cmd *cobra.Command, args []string) error {
21+
return local.ServerRun(cmd.Context())
22+
}

pkg/cli/local_start.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
cli "github.com/acorn-io/runtime/pkg/cli/builder"
7+
"github.com/acorn-io/runtime/pkg/local"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
func NewLocalStart(c CommandContext) *cobra.Command {
12+
cmd := cli.Command(&LocalStart{}, cobra.Command{
13+
Use: "start [flags]",
14+
Aliases: []string{"delete"},
15+
SilenceUsage: true,
16+
Short: "Start local development server",
17+
})
18+
return cmd
19+
}
20+
21+
type LocalStart struct {
22+
}
23+
24+
func (a *LocalStart) Run(cmd *cobra.Command, args []string) error {
25+
c, err := local.NewContainer(cmd.Context())
26+
if err != nil {
27+
return err
28+
}
29+
30+
if _, err := c.Create(cmd.Context(), false); err != nil {
31+
return err
32+
}
33+
34+
if err := c.Start(cmd.Context()); err != nil {
35+
return err
36+
}
37+
38+
fmt.Println("started")
39+
return nil
40+
}

pkg/cli/local_stop.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
cli "github.com/acorn-io/runtime/pkg/cli/builder"
7+
"github.com/acorn-io/runtime/pkg/local"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
func NewLocalStop(c CommandContext) *cobra.Command {
12+
cmd := cli.Command(&LocalStop{}, cobra.Command{
13+
Use: "stop [flags]",
14+
Aliases: []string{"delete"},
15+
SilenceUsage: true,
16+
Short: "Stop local development server",
17+
})
18+
return cmd
19+
}
20+
21+
type LocalStop struct {
22+
}
23+
24+
func (a *LocalStop) Run(cmd *cobra.Command, args []string) error {
25+
c, err := local.NewContainer(cmd.Context())
26+
if err != nil {
27+
return err
28+
}
29+
30+
if err := c.Stop(cmd.Context()); err != nil {
31+
return err
32+
}
33+
fmt.Println("stopped")
34+
return nil
35+
}

0 commit comments

Comments
 (0)