Skip to content

Commit

Permalink
Merge pull request #414 from eigr/feat/add-sdk-docker-init
Browse files Browse the repository at this point in the history
feat: add sdk init wrapper
  • Loading branch information
sleipnir authored Jan 12, 2025
2 parents dfdb72e + c3cd56c commit cb445b1
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tools/sdk-init/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Dockerfile for test
FROM python:3.11-slim

# Install necessary dependencies for the example Python app
RUN pip install flask

# Set the working directory
WORKDIR /app

# Copy the binary from the builder stage
COPY ./bin/sdk-init /usr/local/bin/sdk-init

# Add the example Python app
COPY ./example-app/app.py /app
COPY ./example-app/protos /protos

# Expose the Flask application port
EXPOSE 5000

# Entrypoint runs the main binary first
ENTRYPOINT ["sdk-init"]

# CMD runs the Flask application
CMD ["python", "app.py"]
Binary file added tools/sdk-init/bin/sdk-init
Binary file not shown.
27 changes: 27 additions & 0 deletions tools/sdk-init/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"log"
"os"

"sdk-init/pkg/copier"
"sdk-init/pkg/runner"
)

func main() {
srcDir := "/protos"
destDir := "/shared/protos"

if err := copier.CopyDir(srcDir, destDir); err != nil {
log.Fatalf("Error copying files: %v", err)
}
log.Println("Files copied successfully.")

if len(os.Args) > 1 {
if err := runner.RunCommand(os.Args[1], os.Args[2:]...); err != nil {
log.Fatalf("Error executing command: %v", err)
}
} else {
log.Println("No command specified. Finishing...")
}
}
14 changes: 14 additions & 0 deletions tools/sdk-init/example-app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from flask import Flask, jsonify

app = Flask(__name__)

@app.route("/")
def index():
return jsonify({"message": "User application is running!"})

@app.route("/status")
def status():
return jsonify({"status": "ok", "description": "Flask app is healthy!"})

if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
Empty file.
3 changes: 3 additions & 0 deletions tools/sdk-init/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module sdk-init

go 1.18
6 changes: 6 additions & 0 deletions tools/sdk-init/internal/shared/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package shared

const (
DefaultSrcDir = "/protos"
DefaultDestDir = "/shared/protos"
)
37 changes: 37 additions & 0 deletions tools/sdk-init/pkg/copier/copier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package copier

import (
"io"
"os"
"path/filepath"
)

func CopyDir(src string, dest string) error {
return filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

relPath, _ := filepath.Rel(src, path)
destPath := filepath.Join(dest, relPath)

if info.IsDir() {
return os.MkdirAll(destPath, info.Mode())
}

srcFile, err := os.Open(path)
if err != nil {
return err
}
defer srcFile.Close()

destFile, err := os.Create(destPath)
if err != nil {
return err
}
defer destFile.Close()

_, err = io.Copy(destFile, srcFile)
return err
})
}
14 changes: 14 additions & 0 deletions tools/sdk-init/pkg/runner/runner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package runner

import (
"os"
"os/exec"
)

func RunCommand(cmd string, args ...string) error {
command := exec.Command(cmd, args...)
command.Stdout = os.Stdout
command.Stderr = os.Stderr

return command.Run()
}
Empty file.

0 comments on commit cb445b1

Please sign in to comment.