Skip to content

Commit a7e3946

Browse files
author
andream16
committed
Making sure to mount .smithy directory for sharing
findings; running images on platforms that are not linux/amd64; move main to root to fix go install issues.
1 parent 8e52a33 commit a7e3946

File tree

5 files changed

+90
-79
lines changed

5 files changed

+90
-79
lines changed
Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
1-
name: example-component
2-
description: "This is an example component that demonstrates its functionality."
3-
type: target
1+
name: "git-clone"
2+
description: "Clones a repository"
3+
type: "target"
44
parameters:
5-
- name: input-path
6-
type: string
7-
value: "/data/input"
8-
- name: max-retries
9-
type: const:string
10-
value: "3"
11-
- name: allowed-users
12-
type: list:string
13-
value:
14-
- user1
15-
- user2
16-
- user3
5+
- name: "git_clone_repo_url"
6+
type: "string"
7+
value: "https://github.com/0c34/govwa.git"
8+
- name: "git_clone_reference"
9+
type: "string"
10+
value: "master"
11+
- name: "git_clone_magic_arg"
12+
type: "const:string"
13+
value: "-a 1 -b 2 -c 3"
1714
steps:
18-
- name: fetch-data
19-
args:
20-
- "--source=/data/source"
21-
- "--destination=/data/destination"
15+
- name: "clone-repo"
2216
env_vars:
23-
API_KEY: "your-api-key"
24-
DEBUG: "true"
25-
executable: "/usr/local/bin/fetcher"
26-
image: "example/fetcher:latest"
27-
script: ""
28-
- name: process-data
29-
args:
30-
- "--input=/data/destination"
31-
- "--output=/data/processed"
32-
env_vars:
33-
THREADS: "4"
34-
executable: "/usr/local/bin/processor"
35-
image: "example/processor:latest"
36-
script: ""
17+
GIT_CLONE_REPO_URL: "{{ parameters.git_clone_repo_url }}"
18+
GIT_CLONE_REFERENCE: "{{ parameters.git_clone_reference }}"
19+
GIT_CLONE_MAGIC_ARG: "{{- with shlex parameters.git_clone_magic_arg -}}"
20+
image: "localhost:5000/components/targets/git-clone:latest"

smithyctl/internal/engine/docker/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ type executor struct {
2424
// NewExecutor returns a new docker executor.
2525
func NewExecutor(cli *client.Client) (*executor, error) {
2626
// // Using available docker setup.
27-
// cli, err := client.NewClientWithOpts(client.FromEnv)
28-
// if err != nil {
29-
// return nil, errors.Errorf("failed to create docker client: %w", err)
30-
// }
27+
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
28+
if err != nil {
29+
return nil, errors.Errorf("failed to create docker client: %w", err)
30+
}
3131
return &executor{dockerClient: cli}, nil
3232
}
3333

smithyctl/internal/engine/engine.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"maps"
99
"os"
1010
"path"
11+
"path/filepath"
1112
"slices"
1213
"text/template"
1314

@@ -246,7 +247,15 @@ func (e *executor) executeStep(
246247
return errors.Errorf("%s: could not render step: %w", step.Name, err)
247248
}
248249

249-
volumeBindings := []string{}
250+
absPath, err := filepath.Abs(".")
251+
if err != nil {
252+
return errors.Errorf("failed to determine absolute path: %w", err)
253+
}
254+
255+
volumeBindings := []string{
256+
path.Join(absPath, fmt.Sprintf("%s:/workspace", smithyDir)),
257+
}
258+
250259
for _, stepVolume := range stepVolumes {
251260
volumeBindings = append(volumeBindings, stepVolume.hostPath+":"+stepVolume.mountPath)
252261
}
@@ -274,11 +283,6 @@ func (e *executor) executeStep(
274283
Cmd: step.Args,
275284
EnvVars: envVars,
276285
VolumeBindings: volumeBindings,
277-
// Standardising the platform to avoid not fun issues on different OS/ARCH.
278-
Platform: &ocispec.Platform{
279-
Architecture: "amd64",
280-
OS: "linux",
281-
},
282286
},
283287
); err != nil {
284288
return errors.Errorf("failed to execute step '%s': %w", step.Name, err)

smithyctl/internal/engine/engine_test.go

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package engine_test
33
import (
44
"context"
55
"fmt"
6+
"path"
7+
"path/filepath"
68
"slices"
79
"testing"
810
"time"
911

10-
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
1112
"github.com/stretchr/testify/require"
1213
"go.uber.org/mock/gomock"
1314

@@ -64,6 +65,9 @@ func TestExecutor_Execute(t *testing.T) {
6465
instanceID, err := uuid.Parse("37087cc2-e4ba-4fe0-8230-cda372778ed7")
6566
require.NoError(t, err)
6667

68+
absPath, err := filepath.Abs(".")
69+
require.NoError(t, err)
70+
6771
var (
6872
ctx, cancel = context.WithTimeout(context.Background(), time.Second)
6973
ctrl = gomock.NewController(t)
@@ -220,16 +224,10 @@ func TestExecutor_Execute(t *testing.T) {
220224
require.NoError(t, err)
221225
require.NotNil(t, exe)
222226

223-
var (
224-
envVars = []string{
225-
fmt.Sprintf("SMITHY_INSTANCE_ID=%s", instanceID.String()),
226-
"SMITHY_LOG_LEVEL=debug",
227-
}
228-
platform = &ocispec.Platform{
229-
Architecture: "amd64",
230-
OS: "linux",
231-
}
232-
)
227+
var envVars = []string{
228+
fmt.Sprintf("SMITHY_INSTANCE_ID=%s", instanceID.String()),
229+
"SMITHY_LOG_LEVEL=debug",
230+
}
233231

234232
t.Run("it executes a workflow correctly", func(t *testing.T) {
235233
gomock.InOrder(
@@ -243,10 +241,10 @@ func TestExecutor_Execute(t *testing.T) {
243241
Executable: "/bin/clone",
244242
EnvVars: appendAndSort(envVars, "REPO_URL=github.com/andream16/tree"),
245243
VolumeBindings: []string{
244+
path.Join(absPath, fmt.Sprintf("%s:/workspace", ".smithy")),
246245
sourceCodeHostPath + ":" + sourceCodeMountPath,
247246
},
248-
Cmd: []string{"/workspace/source-code"},
249-
Platform: platform,
247+
Cmd: []string{"/workspace/source-code"},
250248
},
251249
).
252250
Return(nil),
@@ -261,11 +259,11 @@ func TestExecutor_Execute(t *testing.T) {
261259
Executable: "/bin/prescan",
262260
EnvVars: envVars,
263261
VolumeBindings: []string{
262+
path.Join(absPath, fmt.Sprintf("%s:/workspace", ".smithy")),
264263
scratchHostPath + ":" + scratchMountPath,
265264
sourceCodeHostPath + ":" + sourceCodeMountPath,
266265
},
267-
Cmd: []string{"--from=/workspace/source-code", "--to=/workspace/scratch"},
268-
Platform: platform,
266+
Cmd: []string{"--from=/workspace/source-code", "--to=/workspace/scratch"},
269267
},
270268
).
271269
Return(nil),
@@ -280,10 +278,10 @@ func TestExecutor_Execute(t *testing.T) {
280278
Executable: "/bin/scan",
281279
EnvVars: envVars,
282280
VolumeBindings: []string{
281+
path.Join(absPath, fmt.Sprintf("%s:/workspace", ".smithy")),
283282
scratchHostPath + ":" + scratchMountPath,
284283
},
285-
Cmd: []string{"/workspace/scratch"},
286-
Platform: platform,
284+
Cmd: []string{"/workspace/scratch"},
287285
},
288286
).
289287
Return(nil),
@@ -298,10 +296,10 @@ func TestExecutor_Execute(t *testing.T) {
298296
Executable: "/bin/scan",
299297
EnvVars: appendAndSort(envVars, "FROM=/workspace/source-code", "TO=/workspace/scratch"),
300298
VolumeBindings: []string{
299+
path.Join(absPath, fmt.Sprintf("%s:/workspace", ".smithy")),
301300
scratchHostPath + ":" + scratchMountPath,
302301
sourceCodeHostPath + ":" + sourceCodeMountPath,
303302
},
304-
Platform: platform,
305303
},
306304
).
307305
Return(nil),
@@ -311,12 +309,13 @@ func TestExecutor_Execute(t *testing.T) {
311309
RunAndWait(
312310
ctx,
313311
engine.ContainerConfig{
314-
Name: enricherComponentStepName,
315-
Image: enricherComponentImage,
316-
Executable: "/bin/enrich",
317-
VolumeBindings: []string{},
318-
EnvVars: envVars,
319-
Platform: platform,
312+
Name: enricherComponentStepName,
313+
Image: enricherComponentImage,
314+
Executable: "/bin/enrich",
315+
VolumeBindings: []string{
316+
path.Join(absPath, fmt.Sprintf("%s:/workspace", ".smithy")),
317+
},
318+
EnvVars: envVars,
320319
},
321320
).
322321
Return(nil),
@@ -326,12 +325,13 @@ func TestExecutor_Execute(t *testing.T) {
326325
RunAndWait(
327326
ctx,
328327
engine.ContainerConfig{
329-
Name: filterComponentStepName,
330-
Image: filterComponentImage,
331-
Executable: "/bin/filter",
332-
VolumeBindings: []string{},
333-
EnvVars: envVars,
334-
Platform: platform,
328+
Name: filterComponentStepName,
329+
Image: filterComponentImage,
330+
Executable: "/bin/filter",
331+
VolumeBindings: []string{
332+
path.Join(absPath, fmt.Sprintf("%s:/workspace", ".smithy")),
333+
},
334+
EnvVars: envVars,
335335
},
336336
).
337337
Return(nil),
@@ -341,15 +341,16 @@ func TestExecutor_Execute(t *testing.T) {
341341
RunAndWait(
342342
ctx,
343343
engine.ContainerConfig{
344-
Name: reporterComponentStepName,
345-
Image: reporterComponentImage,
346-
Executable: "/bin/report",
347-
VolumeBindings: []string{},
344+
Name: reporterComponentStepName,
345+
Image: reporterComponentImage,
346+
Executable: "/bin/report",
347+
VolumeBindings: []string{
348+
path.Join(absPath, fmt.Sprintf("%s:/workspace", ".smithy")),
349+
},
348350
Cmd: []string{
349351
"-arg1=1",
350352
},
351-
EnvVars: envVars,
352-
Platform: platform,
353+
EnvVars: envVars,
353354
},
354355
).
355356
Return(nil),

smithyctl/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"log"
5+
6+
"github.com/smithy-security/smithy/smithyctl/command/component"
7+
"github.com/smithy-security/smithy/smithyctl/command/version"
8+
"github.com/smithy-security/smithy/smithyctl/command/workflow"
9+
"github.com/smithy-security/smithy/smithyctl/internal/command"
10+
)
11+
12+
func main() {
13+
if err := command.
14+
NewRootCommand(
15+
version.NewCommand(),
16+
component.NewCommand(),
17+
workflow.NewCommand(),
18+
).
19+
Execute(); err != nil {
20+
log.Fatalf("could not execute smithyctl: %v", err)
21+
}
22+
}

0 commit comments

Comments
 (0)