Skip to content

add in the ability to do a single cache #393

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions generators/containers/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func BuildConfig(image string) docker.ContainerConfig {
}
}

cache := fmt.Sprintf("nanobox_%s_cache:/mnt/cache", env)
configModel, _ := models.LoadConfig()
if configModel.Cache == "shared" {
cache = "nanobox_cache:/mtn/cache"
}

conf := docker.ContainerConfig{
Name: BuildName(),
Image: image,
Expand All @@ -35,15 +41,14 @@ func BuildConfig(image string) docker.ContainerConfig {
// fmt.Sprintf("%s%s/cache:/mnt/cache", provider.HostMntDir(), env),
fmt.Sprintf("nanobox_%s_build:/mnt/build", env),
fmt.Sprintf("nanobox_%s_deploy:/mnt/deploy", env),
fmt.Sprintf("nanobox_%s_cache:/mnt/cache", env),
cache,
},
RestartPolicy: "no",
}

// Some CI's have an old kernel and require us to use the virtual network
// this is only in effect for CI's because it automatically reserves an ip on our nanobox
// virtual network and we could have IP conflicts
configModel, _ := models.LoadConfig()
if configModel.CIMode {
conf.Network = "virt"
}
Expand Down
9 changes: 7 additions & 2 deletions generators/containers/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func CompileConfig(image string) docker.ContainerConfig {
}
}

cache := fmt.Sprintf("nanobox_%s_cache:/mnt/cache", env)
configModel, _ := models.LoadConfig()
if configModel.Cache == "shared" {
cache = "nanobox_cache:/mtn/cache"
}

conf := docker.ContainerConfig{
Name: CompileName(),
Image: image,
Expand All @@ -35,15 +41,14 @@ func CompileConfig(image string) docker.ContainerConfig {
// fmt.Sprintf("%s%s/cache:/mnt/cache", provider.HostMntDir(), env),
fmt.Sprintf("nanobox_%s_build:/data", env),
fmt.Sprintf("nanobox_%s_app:/mnt/app", env),
fmt.Sprintf("nanobox_%s_cache:/mnt/cache", env),
cache,
},
RestartPolicy: "no",
}

// Some CI's have an old kernel and require us to use the virtual network
// this is only in effect for CI's because it automatically reserves an ip on our nanobox
// virtual network and we could have IP conflicts
configModel, _ := models.LoadConfig()
if configModel.CIMode {
conf.Network = "virt"
}
Expand Down
8 changes: 7 additions & 1 deletion generators/containers/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func DevConfig(appModel *models.App) docker.ContainerConfig {
code = fmt.Sprintf("%s:/app", config.LocalDir())
}

cache := fmt.Sprintf("nanobox_%s_cache:/mnt/cache", appModel.EnvID)
configModel, _ := models.LoadConfig()
if configModel.Cache == "shared" {
cache = "nanobox_cache:/mtn/cache"
}

config := docker.ContainerConfig{
Name: fmt.Sprintf("nanobox_%s", appModel.ID),
Image: image, // this will need to be configurable some time
Expand All @@ -39,7 +45,7 @@ func DevConfig(appModel *models.App) docker.ContainerConfig {
// fmt.Sprintf("%s%s/build:/data", provider.HostMntDir(), appModel.EnvID),
// fmt.Sprintf("%s%s/cache:/mnt/cache", provider.HostMntDir(), appModel.EnvID),
fmt.Sprintf("nanobox_%s_build:/data", appModel.EnvID),
fmt.Sprintf("nanobox_%s_cache:/mnt/cache", appModel.EnvID),
cache,
},
RestartPolicy: "no",
}
Expand Down
10 changes: 8 additions & 2 deletions generators/containers/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import (
// PublishConfig generate the container configuration for the build container
func PublishConfig(image string) docker.ContainerConfig {
env := config.EnvID()

cache := fmt.Sprintf("nanobox_%s_cache:/mnt/cache", env)
configModel, _ := models.LoadConfig()
if configModel.Cache == "shared" {
cache = "nanobox_cache:/mtn/cache"
}

config := docker.ContainerConfig{
Name: PublishName(),
Image: image,
Expand All @@ -22,7 +29,7 @@ func PublishConfig(image string) docker.ContainerConfig {
// fmt.Sprintf("%s%s/cache:/mnt/cache", provider.HostMntDir(), env),
// fmt.Sprintf("%s%s/deploy:/mnt/deploy", provider.HostMntDir(), env),
fmt.Sprintf("nanobox_%s_app:/mnt/app", env),
fmt.Sprintf("nanobox_%s_cache:/mnt/cache", env),
cache,
fmt.Sprintf("nanobox_%s_deploy:/mnt/deploy", env),
},
RestartPolicy: "no",
Expand All @@ -31,7 +38,6 @@ func PublishConfig(image string) docker.ContainerConfig {
// Some CI's have an old kernel and require us to use the virtual network
// this is only in effect for CI's because it automatically reserves an ip on our nanobox
// virtual network and we could have IP conflicts
configModel, _ := models.LoadConfig()
if configModel.CIMode {
config.Network = "virt"
}
Expand Down
9 changes: 9 additions & 0 deletions models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
DockerMachineNetworkSpace string `json:"docker-machine-network-space"`
NativeNetworkSpace string `json:"native-network-space"`

Cache string `json:cache`
SshKey string `json:"ssh-key"`

Anonymous bool `json:"anonymous"`
Expand Down Expand Up @@ -84,6 +85,14 @@ func (c *Config) makeValid() {
c.SshKey = "default"
}

if c.Cache == "" {
c.Cache = "single"
}

if c.Cache != "single" && c.Cache != "shared" {
c.Cache = "single"
}

if c.LockPort == 0 {
c.LockPort = 12345
}
Expand Down
5 changes: 5 additions & 0 deletions processors/implode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"

"github.com/nanobox-io/golang-docker-client"

"github.com/nanobox-io/nanobox/commands/registry"
"github.com/nanobox-io/nanobox/models"
"github.com/nanobox-io/nanobox/processors/env"
Expand All @@ -30,6 +32,9 @@ func Implode() error {
}
}

// remove any shared caches if any
docker.VolumeRemove("nanobox_cache")

// destroy the provider
if err := provider.Destroy(); err != nil {
return util.ErrorAppend(err, "failed to destroy the provider")
Expand Down