-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #414 from eigr/feat/add-sdk-docker-init
feat: add sdk init wrapper
- Loading branch information
Showing
10 changed files
with
125 additions
and
0 deletions.
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,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 not shown.
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,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...") | ||
} | ||
} |
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,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.
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 @@ | ||
module sdk-init | ||
|
||
go 1.18 |
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 @@ | ||
package shared | ||
|
||
const ( | ||
DefaultSrcDir = "/protos" | ||
DefaultDestDir = "/shared/protos" | ||
) |
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,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 | ||
}) | ||
} |
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,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.