-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathconstants.go
72 lines (60 loc) · 2.22 KB
/
constants.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package constants
import (
"errors"
"fmt"
"path/filepath"
)
const (
// WorkspacesDir is the path to the directory where
// all workspaces are stored by default.
WorkspacesDir = "/workspaces"
// EmptyWorkspaceDir is the path to a workspace that has
// nothing going on... it's empty!
EmptyWorkspaceDir = WorkspacesDir + "/empty"
// defaultMagicDir is the default working location for envbuilder.
// This is a special directory that must not be modified by the user
// or images. This is intentionally unexported.
defaultMagicDir = "/.envbuilder"
// MagicTempDir is a directory inside the build context inside which
// we place files referenced by MagicDirectives.
MagicTempDir = ".envbuilder.tmp"
// MagicDirectives are directives automatically appended to Dockerfiles
// when pushing the image. These directives allow the built image to be
// 're-used'.
MagicDirectives = `
COPY --chmod=0755 .envbuilder.tmp/envbuilder /.envbuilder/bin/envbuilder
COPY --chmod=0644 .envbuilder.tmp/image /.envbuilder/image
USER root
WORKDIR /
ENTRYPOINT ["/.envbuilder/bin/envbuilder"]
`
)
// ErrNoFallbackImage is returned when no fallback image has been specified.
var ErrNoFallbackImage = errors.New("no fallback image has been specified")
// MagicDir is a working directory for envbuilder. We use this to
// store files that are used when building images.
type MagicDir string
// String returns the string representation of the MagicDir.
func (m MagicDir) String() string {
if m == "" {
// Instead of the zero value, use defaultMagicDir.
return defaultMagicDir
}
return filepath.Join("/", string(m))
}
// MagicDir implements fmt.Stringer.
var _ fmt.Stringer = MagicDir("")
// MagicFile is a file that is created in the workspace
// when envbuilder has already been run. This is used
// to skip building when a container is restarting.
// e.g. docker stop -> docker start
func (m MagicDir) Built() string {
return filepath.Join(m.String(), "built")
}
// MagicImage is a file that is created in the image when
// envbuilder has already been run. This is used to skip
// the destructive initial build step when 'resuming' envbuilder
// from a previously built image.
func (m MagicDir) Image() string {
return filepath.Join(m.String(), "image")
}