Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting_tests #34

Merged
merged 49 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3555c86
mounting a volume to buildkit
ashpect Aug 16, 2024
8cc4cc2
squash last 12 commits
ashpect Aug 17, 2024
b9b6cc4
remove toml
ashpect Aug 23, 2024
21ff089
remove volume
ashpect Aug 23, 2024
e94bce1
retrigger tests
ashpect Aug 25, 2024
2f12af4
making import export dynamic
ashpect Aug 25, 2024
b866a8f
Merge pull request #7 from ashpect/feature
ashpect Aug 25, 2024
5a0be01
set the startup flag
ashpect Aug 26, 2024
ec2cba0
Add tests support for startup & refactoring
ashpect Aug 26, 2024
3d8741e
testing
ashpect Aug 26, 2024
26f15d1
testing
ashpect Aug 26, 2024
900787f
testing
ashpect Aug 26, 2024
dea15e5
testing
ashpect Aug 26, 2024
1986560
testing
ashpect Aug 26, 2024
de734f0
testing
ashpect Aug 26, 2024
3827c3f
testing
ashpect Aug 26, 2024
09600b0
testing
ashpect Aug 26, 2024
7e64702
testing
ashpect Aug 26, 2024
cffdc7a
testing
ashpect Aug 26, 2024
7e1ec98
was sh all along
ashpect Aug 26, 2024
52d516f
fix startup string to bool
ashpect Aug 26, 2024
e5628ac
removing ts for testing as building it alone fails
ashpect Aug 26, 2024
57e62f0
runtime error while building c
ashpect Aug 26, 2024
e592227
now go failed
ashpect Aug 26, 2024
3849bd7
rust failed
ashpect Aug 26, 2024
86d5a8c
just py,rb,node
ashpect Aug 26, 2024
84ad0a9
just py,rb,node
ashpect Aug 26, 2024
b3c8e0e
trigger all the tests
ashpect Aug 26, 2024
7296e58
trigger all the tests
ashpect Aug 26, 2024
e862445
trigger all the tests
ashpect Aug 26, 2024
4e59b6a
trigger all the tests
ashpect Aug 26, 2024
0851dab
trigger all the tests
ashpect Aug 26, 2024
c5088de
trigger all the tests startup with cli, i am soooo dumb
ashpect Aug 26, 2024
c0cb671
i think this might work now
ashpect Aug 26, 2024
a6dfdcb
final testing
ashpect Aug 26, 2024
ec7aa45
retrigger
ashpect Aug 26, 2024
f2b8263
what happens if i trigger tests with only runtime build
ashpect Aug 26, 2024
b327a85
retrigger with backtrace added
ashpect Aug 26, 2024
5367920
add diff registry for run time/dev to isolate and retrigger tests wit…
ashpect Aug 26, 2024
1834ab2
disable backtrace like before, this test should fail
ashpect Aug 26, 2024
e416581
triggering only the startup tests with backtrace enabled
ashpect Aug 26, 2024
2eaffdc
enable backtrace,both issues resolved, very demure, very mindful
ashpect Aug 26, 2024
149d41a
Merge ashpect/master into ashpect/feature
ashpect Aug 26, 2024
34af3a6
cleanup and enable all tests
ashpect Aug 26, 2024
deefc5e
only add startup-rootless and startup-client as tests
ashpect Aug 26, 2024
16e573b
Seperated tests
ashpect Aug 26, 2024
9581f7e
Merge pull request #8 from ashpect/feature
ashpect Aug 26, 2024
534bd40
linting tests
ashpect Aug 27, 2024
3071d1a
fix lint
ashpect Aug 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: golangci-lint
on:
push:
branches:
- main
- master
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read

jobs:
golangci:
strategy:
matrix:
go: [stable]
os: [ubuntu-latest, macos-latest, windows-latest]
name: lint
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
run: ./test/test.sh rootless

- name: Test Daemon
run: ./test/test.sh client
run: ./test/test.sh client
38 changes: 38 additions & 0 deletions .github/workflows/startuptest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build and Test MetaCall Builder for startup flow
# Seperate because the space is limited in the github actions

on:
push:
branches:
- master
tags:
- "v*.*.*"
pull_request:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2
with:
fetch-depth: 0

# TODO:
# - name: Lint
# run: docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.59.1 golangci-lint run -v --enable-all

- name: Build
run: docker compose build

- name: Test Binary
env:
BUILDER_ARGS: "runtime rb"
run: docker compose up --exit-code-from binary binary

- name: Test Startup-Rootless
run: ./test/test.sh rootless startup

- name: Test Startup-Daemon
run: ./test/test.sh client startup
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ FROM moby/buildkit:master-rootless AS builder_rootless

COPY --from=builder_binary --chown=user:user /builder /home/user/builder

# TO-DO : Replace with copying from scripts locally
RUN printf '#!/bin/sh\n\
export BUILDKITD_FLAGS=--oci-worker-no-process-sandbox\n\
/home/user/builder $@ | buildctl-daemonless.sh build --output type=image,name=registry:5000/metacall/builder_output,push=true,registry.insecure=true\n'\
/home/user/builder $@ | buildctl-daemonless.sh build \
--export-cache type=registry,ref=${EXPORT_REGISTRY},registry.insecure=true \
--import-cache type=registry,ref=${IMPORT_REGISTRY},registry.insecure=true \
--output type=image,name=registry:5000/metacall/builder_output_$1,push=true,registry.insecure=true\n'\
>> /home/user/builder.sh \
&& chmod 700 /home/user/builder.sh \
&& chmod 700 /home/user/builder
Expand All @@ -46,8 +50,12 @@ COPY --from=builder_binary --chown=root:root /builder /home/builder

RUN apk add --no-cache docker

# TO-DO : Replace with copying from scripts locally
RUN printf '#!/bin/sh\n\
/home/builder $@ | buildctl --addr="docker-container://metacall_builder_buildkit" build --output type=image,name=registry:5000/metacall/builder_output,push=true,registry.insecure=true\n'\
/home/builder $@ | buildctl --addr="docker-container://metacall_builder_buildkit" build \
--export-cache type=registry,ref=${EXPORT_REGISTRY},registry.insecure=true \
--import-cache type=registry,ref=${IMPORT_REGISTRY},registry.insecure=true \
--output type=image,name=registry:5000/metacall/builder_output_$1,push=true,registry.insecure=true\n'\
>> /home/builder.sh \
&& chmod 700 /home/builder.sh \
&& chmod 700 /home/builder
5 changes: 5 additions & 0 deletions cmd/builder/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import (

type RuntimeImageFlags struct {
MetacallCli bool
Startup bool
}

func (i *RuntimeImageFlags) Set(cmd *cobra.Command) {
cmd.Flags().BoolVar(&i.MetacallCli, "cli", false, "set to also get metacall cli in the runtime image")
}

func (i *RuntimeImageFlags) SetStartup(cmd *cobra.Command) {
cmd.Flags().BoolVar(&i.Startup, "startup", false, "startup flag to be used for building image with all languages")
}
10 changes: 8 additions & 2 deletions cmd/builder/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ func NewRuntimeCmd(o *RuntimeOptions) *cobra.Command {
Use: "runtime",
Short: "Build runtime image for MetaCall",
RunE: func(cmd *cobra.Command, args []string) error {

if o.RuntimeImageFlags.MetacallCli {
args = append(args, "node")
}

if o.RuntimeImageFlags.Startup {
args = staging.GetAllLanguages()
}

base := cmd.Context().Value(baseKey{}).(llb.State)

devBaseLang := staging.DevBase(base, branch, args)
devImage := staging.MergeStates(devBaseLang)

runtimeLang:= staging.RuntimeBase(base, branch, args)
runtimeLang := staging.RuntimeBase(base, branch, args)
runtimeImage := staging.MergeStates(runtimeLang)

if o.RuntimeImageFlags.MetacallCli {
Expand All @@ -40,14 +46,14 @@ func NewRuntimeCmd(o *RuntimeOptions) *cobra.Command {
if err != nil {
return err
}

cmd.SetContext(context.WithValue(cmd.Context(), finalKey{}, runtime))
return nil

},
Example: `"builder runtime -b develop --cli nodejs typescript go rust wasm java c cobol"`,
}
o.RuntimeImageFlags.Set(cmd)
o.RuntimeImageFlags.SetStartup(cmd)

return cmd
}
Expand Down
14 changes: 7 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
version: "3.7"

# volumes:
# buildkit:

services:
binary:
image: metacall/builder_binary
Expand All @@ -21,6 +18,10 @@ services:
dockerfile: Dockerfile
target: builder_rootless
entrypoint: /home/user/builder.sh ${BUILDER_ARGS:-}
# entrypoint: /bin/sh -c "sleep infinity"
environment:
IMPORT_REGISTRY: ${IMPORT_REGISTRY:-registry:5000/metacall/builder_startup} # Default won't be needed once we copy the script
EXPORT_REGISTRY: ${EXPORT_REGISTRY:-registry:5000/metacall/builder_dump}
security_opt:
- "seccomp=unconfined"
- "apparmor=unconfined"
Expand All @@ -37,6 +38,9 @@ services:
dockerfile: Dockerfile
target: builder_client
entrypoint: /home/builder.sh ${BUILDER_ARGS:-}
environment:
IMPORT_REGISTRY: ${IMPORT_REGISTRY:-testing}
EXPORT_REGISTRY: ${EXPORT_REGISTRY:-testing}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
# - buildkit:/run/user/1000/buildkit/buildkitd.sock
Expand All @@ -51,10 +55,6 @@ services:
container_name: metacall_builder_buildkit
restart: always
privileged: true
# volumes:
# - /var/run/docker.sock:/var/run/docker.sock
# - /run/containerd/containerd.sock:/run/containerd/containerd.sock
# - buildkit:/run/buildkit/buildkitd.sock
healthcheck:
test: buildctl debug workers
interval: 10s
Expand Down
4 changes: 2 additions & 2 deletions pkg/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func (e Env) MetaCallBuild(arg string) Env {
}

func (e Env) MetacallRuntime(arg string) Env {
e.state = e.state.Run(llb.Shlexf("bash /usr/local/metacall/tools/metacall-runtime.sh base ports clean %v", arg)).
Root() // TODO: Add backtrace
e.state = e.state.Run(llb.Shlexf("bash /usr/local/metacall/tools/metacall-runtime.sh base backtrace ports clean %v", arg)).
Root()

return e
}
Expand Down
38 changes: 19 additions & 19 deletions pkg/staging/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ func copy(src llb.State, srcPath string, dest llb.State, destPath string) llb.St
}))
}

func copyForStates(src llb.State, dst llb.State, srcpaths []string, dstpath string) llb.State {
return dst.With(
copyMultiple(src, srcpaths, dstpath),
)
}

func copyMultiple(src llb.State, srcPaths []string, destPath string) llb.StateOption {
var stateOptions []llb.StateOption
for _, srcPath := range srcPaths {
stateOptions = append(stateOptions, copyFrom(src, srcPath, destPath))
}

return func(s llb.State) llb.State {
for _, stateOption := range stateOptions {
s = stateOption(s)
}
return s
}
}
// Functions which might be useful later, left as comments here :
// func copyForStates(src llb.State, dst llb.State, srcpaths []string, dstpath string) llb.State {
// return dst.With(
// copyMultiple(src, srcpaths, dstpath),
// )
// }

// func copyMultiple(src llb.State, srcPaths []string, destPath string) llb.StateOption {
// var stateOptions []llb.StateOption
// for _, srcPath := range srcPaths {
// stateOptions = append(stateOptions, copyFrom(src, srcPath, destPath))
// }
// return func(s llb.State) llb.State {
// for _, stateOption := range stateOptions {
// s = stateOption(s)
// }
// return s
// }
// }
27 changes: 17 additions & 10 deletions pkg/staging/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
)

var languageMap = map[string]string{
"base": "base",
"py": "python",
"rb": "ruby",
"py": "python",
"rb": "ruby",
// "netcore": "netcore",
// "netcore2": "netcore2",
// "netcore5": "netcore5",
Expand All @@ -22,15 +21,15 @@ var languageMap = map[string]string{
// "v8rep52": "v8rep52",
// "v8rep51": "v8rep51",
"node": "nodejs",
"ts": "typescript",
// "ts": "typescript",
// "file": "file",
// "rpc": "rpc",
"wasm": "wasm",
"java": "java",
"c": "c",
"cob": "cobol",
"go": "go",
"rs": "rust",
// "wasm": "wasm",
// "java": "java",
// // "c": "c",
// "cob": "cobol",
// "go": "go",
// "rs": "rust",
// "backtrace" : "backtrace",
// "sandbox" : "sandbox",
}
Expand Down Expand Up @@ -135,3 +134,11 @@ func MergeStates(individualLangStates map[string]llb.State) llb.State {
}
return llb.Merge(states)
}

func GetAllLanguages() []string {
langs := []string{}
for lang := range languageMap {
langs = append(langs, lang)
}
return langs
}
File renamed without changes.
20 changes: 20 additions & 0 deletions scripts/builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh\n\
export BUILDKITD_FLAGS=--oci-worker-no-process-sandbox\n\

if [ -z "$EXPORT_REGISTRY" ]; then
EXPORT_REGISTRY="registry:5000/metacall/builder_cache"
fi

if [ -z "$IMPORT_REGISTRY" ]; then
IMPORT_REGISTRY="registry:5000/metacall/builder_startup"
fi

if [ -z "$BUILDER_BINARY" ]; then
BUILDER_BINARY="/home/user/builder"
fi


${BUILDER_BINARY} $@ | buildctl-daemonless.sh build \
--export-cache type=registry,ref=${EXPORT_REGISTRY},registry.insecure=true \
--import-cache type=registry,ref=${IMPORT_REGISTRY},registry.insecure=true \
--output type=image,name=registry:5000/metacall/builder_output,push=true,registry.insecure=true\n'\
Loading
Loading