This repository has been archived by the owner on Aug 20, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 07e6365
Showing
3,790 changed files
with
1,071,281 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
* | ||
!cmd | ||
!pkg | ||
!vendor | ||
!go.* | ||
!*.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.idea | ||
/bin | ||
/k3c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
FROM golang:1.13.4-alpine3.10 as build | ||
RUN apk -U --no-cache add bash git gcc musl-dev docker vim less file curl wget ca-certificates jq linux-headers zlib-dev tar zip squashfs-tools npm coreutils \ | ||
python3 py3-pip python3-dev openssl-dev libffi-dev libseccomp libseccomp-dev make libuv-static | ||
COPY . /go/src/github.com/rancher/k3c | ||
ENV GO111MODULE=off | ||
RUN cd /go/src/github.com/rancher/k3c && \ | ||
go build -ldflags "-extldflags -static -s" -o /bin/k3c main.go | ||
|
||
FROM rancher/k3s:v1.0.0 as data | ||
RUN rm -rf etc/strongswan var run lib \ | ||
bin/swanctl \ | ||
bin/charon \ | ||
bin/containerd \ | ||
kubectl \ | ||
k3s-server \ | ||
k3s-agent \ | ||
k3s \ | ||
ctr \ | ||
crictl | ||
|
||
FROM scratch as bin | ||
COPY --from=build /bin/k3c /bin/k3c | ||
|
||
FROM scratch | ||
COPY --from=bin /bin/ /bin | ||
COPY --from=data /bin/ /bin | ||
COPY --from=data /etc/ /etc | ||
COPY --from=data /tmp/ /tmp | ||
VOLUME /var/lib/rancher/k3c | ||
CMD ["/bin/k3c","daemon", "--bridge-cidr=172.19.0.0/16"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
K3C = "k3c" | ||
|
||
all: | ||
${K3C} build --target bin -o ./ . | ||
|
||
clean: | ||
rm -rf bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package attach | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/rancher/k3c/pkg/cliclient" | ||
"github.com/rancher/k3c/pkg/client" | ||
"github.com/rancher/k3c/pkg/remote/apis/k3c/v1alpha1" | ||
"github.com/rancher/k3c/pkg/stream" | ||
"github.com/rancher/k3c/pkg/validate" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
type Attach struct { | ||
NoStdin bool `usage:"Do not attach STDIN"` | ||
} | ||
|
||
func (a *Attach) Run(ctx *cli.Context) error { | ||
if err := validate.NArgs(ctx, "attach", 1, 1); err != nil { | ||
return err | ||
} | ||
|
||
c, err := cliclient.New(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return RunAttach(ctx.Context, c, ctx.Args().First(), &v1alpha1.AttachOptions{ | ||
NoStdin: a.NoStdin, | ||
}) | ||
} | ||
|
||
func RunAttach(ctx context.Context, c client.Client, containerID string, opts *v1alpha1.AttachOptions) error { | ||
resp, err := c.Attach(ctx, containerID, opts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return stream.Stream(resp.Stdin, resp.TTY, resp.URL) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package build | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/rancher/k3c/pkg/cliclient" | ||
"github.com/rancher/k3c/pkg/client/build" | ||
"github.com/rancher/k3c/pkg/kvfile" | ||
"github.com/rancher/k3c/pkg/validate" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
type Build struct { | ||
AddHost []string `usage:"Add a custom host-to-IP mapping (host:ip)"` | ||
BuildArg []string `usage:"Set build-time variables"` | ||
CacheFrom []string `usage:"Images to consider as cache sources"` | ||
F_File string `usage:"Name of the Dockerfile (Default is 'PATH/Dockerfile')"` | ||
Label []string `usage:"Set metadata for an image"` | ||
NoCache bool `usage:"Do not use cache when building the image"` | ||
O_Output string `usage:"Output directory or - for stdout. (adv. format: type=local,dest=path)"` | ||
Progress string `usage:"Set type of progress output (auto, plain, tty). Use plain to show container output" default:"auto"` | ||
Q_Quiet bool `usage:"Suppress the build output and print image ID on success"` | ||
Secret []string `usage:"Secret file to expose to the build (only if BuildKit enabled): id=mysecret,src=/local/secret"` | ||
T_Tag []string `usage:"Name and optionally a tag in the 'name:tag' format"` | ||
Target string `usage:"Set the target build stage to build."` | ||
Ssh []string `usage:"SSH agent socket or keys to expose to the build (only if BuildKit enabled) (format: default|<id>[=<socket>|<key>[,<key>]])"` | ||
Pull bool `usage:"Always attempt to pull a newer version of the image"` | ||
} | ||
|
||
func (b *Build) Run(ctx *cli.Context) error { | ||
if err := validate.NArgs(ctx, "build", 1, 1); err != nil { | ||
return err | ||
} | ||
|
||
args, err := kvfile.ReadKVMap(nil, b.AddHost) | ||
if err != nil { | ||
return errors.Wrap(err, "parsing build-arg") | ||
} | ||
|
||
labels, err := kvfile.ReadKVMap(nil, b.Label) | ||
if err != nil { | ||
return errors.Wrap(err, "parsing label") | ||
} | ||
|
||
//if b.T_Tag != "" && b.O_Output != "" { | ||
// return fmt.Errorf("--tag and --output can not be combined") | ||
//} | ||
|
||
opts := &build.BuildOpts{ | ||
CacheFromImages: b.CacheFrom, | ||
Pull: b.Pull, | ||
Args: args, | ||
Label: labels, | ||
Tag: b.T_Tag, | ||
Target: b.Target, | ||
SSH: b.Ssh, | ||
NoCache: b.NoCache, | ||
AddHosts: b.AddHost, | ||
Dockerfile: b.F_File, | ||
Progress: build.ProgressStyle(b.Progress), | ||
Secrets: b.Secret, | ||
Output: b.O_Output, | ||
} | ||
|
||
if b.Q_Quiet { | ||
opts.Progress = build.ProgressStyleNone | ||
} | ||
|
||
client, err := cliclient.NewBuilder(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer client.Close() | ||
|
||
contextDir := ctx.Args().First() | ||
|
||
var closer io.Closer | ||
opts.Dockerfile, contextDir, closer, err = readStdinContent(opts.Dockerfile, contextDir) | ||
if err != nil { | ||
return err | ||
} | ||
defer closer.Close() | ||
|
||
digest, err := client.Build(ctx.Context, contextDir, opts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if digest != "" { | ||
fmt.Println(digest) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func readStdinContent(dockerfile, contextDir string) (string, string, io.Closer, error) { | ||
if dockerfile != "-" && contextDir != "-" { | ||
return dockerfile, contextDir, (*dirCleanup)(nil), nil | ||
} | ||
|
||
bytes, err := ioutil.ReadAll(os.Stdin) | ||
if err != nil { | ||
return "", "", nil, err | ||
} | ||
|
||
tempDir, err := ioutil.TempDir("", "k3c-build") | ||
if err != nil { | ||
return "", "", nil, err | ||
} | ||
|
||
tempDockerfile := filepath.Join(tempDir, "Dockerfile") | ||
if err := ioutil.WriteFile(tempDockerfile, bytes, 0600); err != nil { | ||
return "", "", nil, err | ||
} | ||
|
||
if contextDir == "-" { | ||
return tempDockerfile, tempDir, &dirCleanup{Dir: tempDir}, nil | ||
} | ||
|
||
return tempDockerfile, contextDir, &dirCleanup{Dir: tempDir}, nil | ||
} | ||
|
||
type dirCleanup struct { | ||
Dir string | ||
} | ||
|
||
func (d *dirCleanup) Close() error { | ||
if d == nil { | ||
return nil | ||
} | ||
return os.RemoveAll(d.Dir) | ||
} |
Oops, something went wrong.