Skip to content

Commit cb445b1

Browse files
authored
Merge pull request #414 from eigr/feat/add-sdk-docker-init
feat: add sdk init wrapper
2 parents dfdb72e + c3cd56c commit cb445b1

File tree

10 files changed

+125
-0
lines changed

10 files changed

+125
-0
lines changed

tools/sdk-init/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Dockerfile for test
2+
FROM python:3.11-slim
3+
4+
# Install necessary dependencies for the example Python app
5+
RUN pip install flask
6+
7+
# Set the working directory
8+
WORKDIR /app
9+
10+
# Copy the binary from the builder stage
11+
COPY ./bin/sdk-init /usr/local/bin/sdk-init
12+
13+
# Add the example Python app
14+
COPY ./example-app/app.py /app
15+
COPY ./example-app/protos /protos
16+
17+
# Expose the Flask application port
18+
EXPOSE 5000
19+
20+
# Entrypoint runs the main binary first
21+
ENTRYPOINT ["sdk-init"]
22+
23+
# CMD runs the Flask application
24+
CMD ["python", "app.py"]

tools/sdk-init/bin/sdk-init

1.38 MB
Binary file not shown.

tools/sdk-init/cmd/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
7+
"sdk-init/pkg/copier"
8+
"sdk-init/pkg/runner"
9+
)
10+
11+
func main() {
12+
srcDir := "/protos"
13+
destDir := "/shared/protos"
14+
15+
if err := copier.CopyDir(srcDir, destDir); err != nil {
16+
log.Fatalf("Error copying files: %v", err)
17+
}
18+
log.Println("Files copied successfully.")
19+
20+
if len(os.Args) > 1 {
21+
if err := runner.RunCommand(os.Args[1], os.Args[2:]...); err != nil {
22+
log.Fatalf("Error executing command: %v", err)
23+
}
24+
} else {
25+
log.Println("No command specified. Finishing...")
26+
}
27+
}

tools/sdk-init/example-app/app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from flask import Flask, jsonify
2+
3+
app = Flask(__name__)
4+
5+
@app.route("/")
6+
def index():
7+
return jsonify({"message": "User application is running!"})
8+
9+
@app.route("/status")
10+
def status():
11+
return jsonify({"status": "ok", "description": "Flask app is healthy!"})
12+
13+
if __name__ == "__main__":
14+
app.run(host="0.0.0.0", port=5000)

tools/sdk-init/example-app/protos/test.proto

Whitespace-only changes.

tools/sdk-init/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module sdk-init
2+
3+
go 1.18
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package shared
2+
3+
const (
4+
DefaultSrcDir = "/protos"
5+
DefaultDestDir = "/shared/protos"
6+
)

tools/sdk-init/pkg/copier/copier.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package copier
2+
3+
import (
4+
"io"
5+
"os"
6+
"path/filepath"
7+
)
8+
9+
func CopyDir(src string, dest string) error {
10+
return filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
11+
if err != nil {
12+
return err
13+
}
14+
15+
relPath, _ := filepath.Rel(src, path)
16+
destPath := filepath.Join(dest, relPath)
17+
18+
if info.IsDir() {
19+
return os.MkdirAll(destPath, info.Mode())
20+
}
21+
22+
srcFile, err := os.Open(path)
23+
if err != nil {
24+
return err
25+
}
26+
defer srcFile.Close()
27+
28+
destFile, err := os.Create(destPath)
29+
if err != nil {
30+
return err
31+
}
32+
defer destFile.Close()
33+
34+
_, err = io.Copy(destFile, srcFile)
35+
return err
36+
})
37+
}

tools/sdk-init/pkg/runner/runner.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package runner
2+
3+
import (
4+
"os"
5+
"os/exec"
6+
)
7+
8+
func RunCommand(cmd string, args ...string) error {
9+
command := exec.Command(cmd, args...)
10+
command.Stdout = os.Stdout
11+
command.Stderr = os.Stderr
12+
13+
return command.Run()
14+
}

tools/sdk-init/shared/protos/test.proto

Whitespace-only changes.

0 commit comments

Comments
 (0)