-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: Added Controller Methods for making DockerImage and Downloading Files #25
base: main
Are you sure you want to change the base?
Changes from all commits
fb1da7a
55a0e07
7a13d6a
f47bcb2
e321c85
b036367
c6c1221
08d9ed9
69dec3f
d6507fa
f97a495
d1fe0dc
7883350
057fefa
eb20333
99817e1
349f092
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,73 @@ | ||
package controllers | ||
|
||
import "github.com/gin-gonic/gin" | ||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type AWSConfig struct { | ||
AWSAccessKeyID string | ||
AWSSecretAccessKey string | ||
AWSS3Region string | ||
AWSS3Bucket string | ||
AWSS3Client *s3.S3 | ||
} | ||
|
||
func (config AWSConfig) ConnectToAWS() { | ||
// Creating a new session | ||
sess, err := session.NewSession( | ||
&aws.Config{ | ||
Region: aws.String(config.AWSS3Region), | ||
Credentials: credentials.NewStaticCredentials(config.AWSAccessKeyID, config.AWSSecretAccessKey, ""), | ||
}, | ||
) | ||
|
||
if err != nil { | ||
return | ||
} | ||
|
||
config.AWSS3Client = s3.New(sess) | ||
} | ||
|
||
func (config AWSConfig) DownloadFilesFromS3() error { | ||
// Defining Global S3 Client | ||
s3Client := config.AWSS3Client | ||
|
||
// Getting the object to download | ||
downloader := s3.GetObjectInput{ | ||
Bucket: aws.String(config.AWSS3Bucket), | ||
Key: aws.String("test.txt"), | ||
} | ||
|
||
// Downloading the object | ||
result, err := s3Client.GetObject(&downloader) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Creating a Zip file | ||
zipFile, err := os.Create("test.zip") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Copying the object to the zip file | ||
_, err = io.Copy(zipFile, result.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
|
||
} | ||
|
||
|
||
func downloadFilesController(context *gin.Context) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have the downloadFilesController ? |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/client" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func MakeDockerImage(ctx *gin.Context) { | ||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) | ||
if err != nil { | ||
ctx.String(500, "Error creating Docker Client") | ||
return | ||
} | ||
|
||
// Build an image from a Dockerfile in the current directory | ||
buildcontext, err := os.Open("./model.tar") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wasn't the files zip? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to unzip and add the Dockerfile inside. I just made a tar after adding the Dockerfile. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where are we adding the docker image and getting the tar file? |
||
if err != nil { | ||
ctx.String(500, "Error in reading file ", err) | ||
return | ||
} | ||
|
||
// Building an image from the Dockerfile | ||
buildResponse, err := cli.ImageBuild( | ||
context.Background(), | ||
buildcontext, | ||
types.ImageBuildOptions{ | ||
Dockerfile: "model/Dockerfile", | ||
Tags: []string{"my-image:latest"}, | ||
}, | ||
) | ||
if err != nil { | ||
ctx.String(500, "Error in Making Image %v", err) | ||
return | ||
} | ||
|
||
// Reading the output of the build | ||
|
||
// Making a buffer slice of size 1KB | ||
buffer := make([]byte, 1024) | ||
|
||
// Iterating through the build Response body | ||
for { | ||
n, err := buildResponse.Body.Read(buffer) | ||
if n > 0 { | ||
fmt.Print(string(buffer[:n])) | ||
} | ||
if err != nil { | ||
ctx.String(500, "There was an error in building Image") | ||
break | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,32 +2,48 @@ module github.com/LainForge/Neura-Launch-Dashboard/builder | |
|
||
go 1.21 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When did this happen There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷 |
||
|
||
require github.com/gin-gonic/gin v1.9.1 | ||
require ( | ||
github.com/aws/aws-sdk-go v1.45.28 | ||
github.com/gin-gonic/gin v1.9.1 | ||
) | ||
|
||
require ( | ||
github.com/Microsoft/go-winio v0.6.1 // indirect | ||
github.com/bytedance/sonic v1.10.2 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect | ||
github.com/chenzhuoyu/iasm v0.9.0 // indirect | ||
github.com/distribution/reference v0.5.0 // indirect | ||
github.com/docker/distribution v2.8.3+incompatible // indirect | ||
github.com/docker/docker v24.0.6+incompatible // indirect | ||
github.com/docker/go-connections v0.4.0 // indirect | ||
github.com/docker/go-units v0.5.0 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.15.5 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/jmespath/go-jmespath v0.4.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.5 // indirect | ||
github.com/leodido/go-urn v1.2.4 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.11 // indirect | ||
golang.org/x/arch v0.5.0 // indirect | ||
golang.org/x/crypto v0.14.0 // indirect | ||
golang.org/x/mod v0.8.0 // indirect | ||
golang.org/x/net v0.17.0 // indirect | ||
golang.org/x/sys v0.13.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
golang.org/x/tools v0.6.0 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im curious abt how this works... why "test.txt" ?