Skip to content

Commit

Permalink
remote deploy/destroy improvements (#3393)
Browse files Browse the repository at this point in the history
* expand envs for image used in remote deploy

Signed-off-by: adripedriza <adripedriza@gmail.com>

* remove unnecessary consts

Signed-off-by: adripedriza <adripedriza@gmail.com>

* update dockerignore name for destroy

Signed-off-by: adripedriza <adripedriza@gmail.com>

---------

Signed-off-by: adripedriza <adripedriza@gmail.com>
  • Loading branch information
AdrianPedriza committed Feb 20, 2023
1 parent 35f882a commit 8926a1d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
8 changes: 3 additions & 5 deletions cmd/deploy/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ WORKDIR /okteto/src
ENV OKTETO_INVALIDATE_CACHE {{ .RandomInt }}
RUN okteto deploy --log-output=json {{ .DeployFlags }}
`
dockerignoreName = "deploy.dockerignore"
buildOutput = "deploy"
)

type dockerfileTemplateProperties struct {
Expand Down Expand Up @@ -153,7 +151,7 @@ func (rd *remoteDeployCommand) deploy(ctx context.Context, deployOptions *Option
// undo modification of CWD for Build command
os.Chdir(cwd)

buildOptions := build.OptsFromBuildInfo("", "", buildInfo, &types.BuildOptions{Path: cwd, OutputMode: buildOutput})
buildOptions := build.OptsFromBuildInfo("", "", buildInfo, &types.BuildOptions{Path: cwd, OutputMode: "deploy"})
buildOptions.Tag = ""

// we need to call Build() method using a remote builder. This Builder will have
Expand All @@ -176,7 +174,7 @@ func (rd *remoteDeployCommand) cleanUp(ctx context.Context, err error) {
}

func (rd *remoteDeployCommand) createDockerignoreIfNeeded(cwd, tmpDir string) error {
dockerignoreFilePath := fmt.Sprintf("%s/%s", cwd, dockerignoreName)
dockerignoreFilePath := fmt.Sprintf("%s/%s", cwd, ".oktetodeployignore")
if _, err := rd.fs.Stat(dockerignoreFilePath); err != nil {
if !errors.Is(err, os.ErrNotExist) {
return err
Expand All @@ -187,7 +185,7 @@ func (rd *remoteDeployCommand) createDockerignoreIfNeeded(cwd, tmpDir string) er
return err
}

err = afero.WriteFile(rd.fs, fmt.Sprintf("%s/%s", tmpDir, dockerignoreName), dockerignoreContent, 0600)
err = afero.WriteFile(rd.fs, fmt.Sprintf("%s/%s", tmpDir, ".dockerignore"), dockerignoreContent, 0600)
if err != nil {
return err
}
Expand Down
8 changes: 3 additions & 5 deletions cmd/destroy/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ WORKDIR /okteto/src
ENV OKTETO_INVALIDATE_CACHE {{ .RandomInt }}
RUN okteto destroy {{ .DestroyFlags }}
`
dockerignoreName = "deploy.dockerignore"
buildOutput = "deploy"
)

type dockerfileTemplateProperties struct {
Expand Down Expand Up @@ -142,7 +140,7 @@ func (rd *remoteDestroyCommand) destroy(ctx context.Context, opts *Options) erro
// undo modification of CWD for Build command
os.Chdir(cwd)

buildOptions := build.OptsFromBuildInfo("", "", buildInfo, &types.BuildOptions{Path: cwd, OutputMode: buildOutput})
buildOptions := build.OptsFromBuildInfo("", "", buildInfo, &types.BuildOptions{Path: cwd, OutputMode: "deploy"})
buildOptions.Tag = ""

// we need to call Build() method using a remote builder. This Builder will have
Expand All @@ -162,7 +160,7 @@ func (rd *remoteDestroyCommand) destroy(ctx context.Context, opts *Options) erro
}

func (rd *remoteDestroyCommand) createDockerignoreIfNeeded(cwd, tmpDir string) error {
dockerignoreFilePath := fmt.Sprintf("%s/%s", cwd, dockerignoreName)
dockerignoreFilePath := fmt.Sprintf("%s/%s", cwd, ".oktetodeployignore")
if _, err := rd.fs.Stat(dockerignoreFilePath); err != nil {
if !errors.Is(err, os.ErrNotExist) {
return err
Expand All @@ -173,7 +171,7 @@ func (rd *remoteDestroyCommand) createDockerignoreIfNeeded(cwd, tmpDir string) e
return err
}

err = afero.WriteFile(rd.fs, fmt.Sprintf("%s/%s", tmpDir, dockerignoreName), dockerignoreContent, 0600)
err = afero.WriteFile(rd.fs, fmt.Sprintf("%s/%s", tmpDir, ".dockerignore"), dockerignoreContent, 0600)
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/model/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,12 @@ func (m *Manifest) mergeWithOktetoManifest(other *Manifest) {
func (manifest *Manifest) ExpandEnvVars() error {
var err error
if manifest.Deploy != nil {
if manifest.Deploy.Image != "" {
manifest.Deploy.Image, err = envsubst.String(manifest.Deploy.Image)
if err != nil {
return errors.New("could not parse env vars for an image used for remote deploy")
}
}
if manifest.Deploy.ComposeSection != nil && manifest.Deploy.ComposeSection.Stack != nil {
var stackFiles []string
for _, composeInfo := range manifest.Deploy.ComposeSection.ComposesInfo {
Expand Down
16 changes: 16 additions & 0 deletions pkg/model/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ func TestManifestExpandDevEnvs(t *testing.T) {
manifest: &Manifest{},
expectedManifest: &Manifest{},
},
{
name: "expand image for remote deploy",
envs: map[string]string{
"myImage": "test",
},
manifest: &Manifest{
Deploy: &DeployInfo{
Image: "${myImage}",
},
},
expectedManifest: &Manifest{
Deploy: &DeployInfo{
Image: "test",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 8926a1d

Please sign in to comment.