Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Templating Functions & HCL Variables for Artifacts, Deploys #757

Merged
merged 29 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2500531
point to local waypoint-plugin-sdk
mitchellh Nov 1, 2020
3506876
internal/core: update TemplateData if available
mitchellh Nov 1, 2020
8972cd4
internal/pkg/ctystructure: package to convert maps to cty objects
mitchellh Nov 1, 2020
471fb88
internal/core: expose build data as HCL for pushes
mitchellh Nov 1, 2020
38de234
go.mod
mitchellh Nov 1, 2020
8d70562
internal/pkg/ctystructure: handle invalids
mitchellh Nov 1, 2020
4c7a50c
internal/core: more logging
mitchellh Nov 1, 2020
31094f3
go.mod
mitchellh Nov 1, 2020
3a9674e
internal/core: push field is artifact
mitchellh Nov 1, 2020
a6404c5
internal/core: empty context wasn't used
mitchellh Nov 2, 2020
23da822
update waypoint-plugin-sdk
mitchellh Nov 2, 2020
d8e4bb0
internal/core: load components with no config outside of ops
mitchellh Nov 4, 2020
90b5cad
internal/cli: disable auth check
mitchellh Nov 4, 2020
e28a236
internal/config/funcs: templatestring
mitchellh Nov 4, 2020
e3905b8
internal/config/funcs: file functions require absolute path
mitchellh Nov 4, 2020
d78490e
internal/config/funcs: templatefile
mitchellh Nov 4, 2020
092b096
internal/config/funcs: templatedir
mitchellh Nov 4, 2020
3edbba1
internal/config: add template funcs to context
mitchellh Nov 4, 2020
eb1b4db
internal/core: deploy and release have access to templates
mitchellh Nov 5, 2020
16a5f91
internal/core: destroys load their details
mitchellh Nov 5, 2020
48b30a4
internal/core: load default releaser with new deferred config
mitchellh Nov 5, 2020
ccbe88a
internal/config: Operation.Configure for retaining context for plugin
mitchellh Nov 7, 2020
f9720f2
internal/core: use config.Operation.Configure for proper hcl context
mitchellh Nov 7, 2020
a448c71
internal/config/funcs: remove TF-specific error message
mitchellh Nov 7, 2020
0ce8452
go.mod
mitchellh Nov 7, 2020
3fb5e7f
builtin/docker: copy Dockerfile is outside build context
mitchellh Nov 7, 2020
2c0f140
go.mod
mitchellh Nov 7, 2020
7c65a1c
Update builtin/docker/copy.go
mitchellh Nov 9, 2020
1d197f0
internal/core: clearer error if templatedata parsing fails
mitchellh Nov 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions builtin/docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package docker
import (
"bytes"
"context"
"crypto/rand"
"fmt"
"os"
"path"
"path/filepath"
"strings"

"github.com/docker/cli/cli/command/image/build"
"github.com/docker/docker/api/types"
Expand All @@ -16,6 +18,7 @@ import (
"github.com/hashicorp/waypoint-plugin-sdk/component"
"github.com/hashicorp/waypoint-plugin-sdk/docs"
"github.com/hashicorp/waypoint-plugin-sdk/terminal"
"github.com/oklog/ulid/v2"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand Down Expand Up @@ -125,8 +128,26 @@ func (b *Builder) Build(
cli.NegotiateAPIVersion(ctx)

dockerfile := b.config.Dockerfile
if dockerfile != "" {
dockerfile = path.Join(src.Path, dockerfile)
if !filepath.IsAbs(dockerfile) {
dockerfile = filepath.Join(src.Path, dockerfile)
}

// If the dockerfile is outside of our build context, then we copy it
// into our build context.
relDockerfile, err := filepath.Rel(src.Path, dockerfile)
if err != nil || strings.HasPrefix(relDockerfile, "..") {
id, err := ulid.New(ulid.Now(), rand.Reader)
if err != nil {
return nil, err
}

newPath := filepath.Join(src.Path, fmt.Sprintf("Dockerfile-%s", id.String()))
if err := copyFile(dockerfile, newPath); err != nil {
return nil, err
}
defer os.Remove(newPath)

dockerfile = newPath
}

contextDir, relDockerfile, err := build.GetContextFromLocalDir(src.Path, dockerfile)
Expand Down
52 changes: 52 additions & 0 deletions builtin/docker/copy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package docker

import (
"io"
"os"
)

// From: https://gist.github.com/m4ng0squ4sh/92462b38df26839a3ca324697c8cba04
mitchellh marked this conversation as resolved.
Show resolved Hide resolved

// copyFile copies the contents of the file named src to the file named
// by dst. The file will be created if it does not already exist. If the
// destination file exists, all it's contents will be replaced by the contents
// of the source file. The file mode will be copied from the source and
// the copied data is synced/flushed to stable storage.
func copyFile(src, dst string) (err error) {
in, err := os.Open(src)
if err != nil {
return
}
defer in.Close()

out, err := os.Create(dst)
if err != nil {
return
}
defer func() {
if e := out.Close(); e != nil {
err = e
}
}()

_, err = io.Copy(out, in)
if err != nil {
return
}

err = out.Sync()
if err != nil {
return
}

si, err := os.Stat(src)
if err != nil {
return
}
err = os.Chmod(dst, si.Mode())
if err != nil {
return
}

return
}