forked from LaconicNetwork/kompose
Added dockerfile key support
Fixes #486 This commit will add `dockerfilepath` key under Dockerstratergy in buildconfig. dockerfilepath allow us to use dockerfiles which are named different than `Dockerfile` which are placed in context directory. for example, for a docker-compose file: ``` version: "2" services: foo: build: context: "./build" dockerfile: "Dockerfile-alternate" command: "sleep 3600" ``` Resulting buildconfig will be: ``` apiVersion: v1 kind: BuildConfig ... ... strategy: dockerStrategy: dockerfilePath: Dockerfile-alternate type: Docker ... ... ```
This commit is contained in:
parent
fba87faa16
commit
ec897ef50f
@ -84,6 +84,7 @@ type ServiceConfig struct {
|
|||||||
Tty bool `compose:"tty" bundle:""`
|
Tty bool `compose:"tty" bundle:""`
|
||||||
MemLimit yaml.MemStringorInt `compose:"mem_limit" bundle:""`
|
MemLimit yaml.MemStringorInt `compose:"mem_limit" bundle:""`
|
||||||
TmpFs []string `compose:"tmpfs" bundle:""`
|
TmpFs []string `compose:"tmpfs" bundle:""`
|
||||||
|
Dockerfile string `compose:"dockerfile" bundle:""`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnvVar holds the environment variable struct of a container
|
// EnvVar holds the environment variable struct of a container
|
||||||
|
|||||||
@ -76,7 +76,6 @@ func checkUnsupportedKey(composeProject *project.Project) []string {
|
|||||||
"Uts": false,
|
"Uts": false,
|
||||||
"ReadOnly": false,
|
"ReadOnly": false,
|
||||||
"Ulimits": false,
|
"Ulimits": false,
|
||||||
"Dockerfile": false,
|
|
||||||
"Net": false,
|
"Net": false,
|
||||||
"Sysctls": false,
|
"Sysctls": false,
|
||||||
"Networks": false, // there are special checks for Network in checkUnsupportedKey function
|
"Networks": false, // there are special checks for Network in checkUnsupportedKey function
|
||||||
@ -321,6 +320,7 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) {
|
|||||||
serviceConfig.ContainerName = composeServiceConfig.ContainerName
|
serviceConfig.ContainerName = composeServiceConfig.ContainerName
|
||||||
serviceConfig.Command = composeServiceConfig.Entrypoint
|
serviceConfig.Command = composeServiceConfig.Entrypoint
|
||||||
serviceConfig.Args = composeServiceConfig.Command
|
serviceConfig.Args = composeServiceConfig.Command
|
||||||
|
serviceConfig.Dockerfile = composeServiceConfig.Build.Dockerfile
|
||||||
|
|
||||||
envs := loadEnvVars(composeServiceConfig.Environment)
|
envs := loadEnvVars(composeServiceConfig.Environment)
|
||||||
serviceConfig.Environment = envs
|
serviceConfig.Environment = envs
|
||||||
|
|||||||
@ -200,7 +200,9 @@ func initBuildConfig(name string, service kobject.ServiceConfig, composeFileDir
|
|||||||
ContextDir: contextDir,
|
ContextDir: contextDir,
|
||||||
},
|
},
|
||||||
Strategy: buildapi.BuildStrategy{
|
Strategy: buildapi.BuildStrategy{
|
||||||
DockerStrategy: &buildapi.DockerBuildStrategy{},
|
DockerStrategy: &buildapi.DockerBuildStrategy{
|
||||||
|
DockerfilePath: service.Dockerfile,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Output: buildapi.BuildOutput{
|
Output: buildapi.BuildOutput{
|
||||||
To: &kapi.ObjectReference{
|
To: &kapi.ObjectReference{
|
||||||
|
|||||||
@ -290,7 +290,8 @@ func TestInitBuildConfig(t *testing.T) {
|
|||||||
repo := "https://git.test.com/org/repo"
|
repo := "https://git.test.com/org/repo"
|
||||||
branch := "somebranch"
|
branch := "somebranch"
|
||||||
sc := kobject.ServiceConfig{
|
sc := kobject.ServiceConfig{
|
||||||
Build: "./build",
|
Build: "./build",
|
||||||
|
Dockerfile: "Dockerfile-alternate",
|
||||||
}
|
}
|
||||||
bc, err := initBuildConfig(serviceName, sc, composeFileDir, repo, branch)
|
bc, err := initBuildConfig(serviceName, sc, composeFileDir, repo, branch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -305,6 +306,7 @@ func TestInitBuildConfig(t *testing.T) {
|
|||||||
"Assert buildconfig source git Ref": {bc.Spec.CommonSpec.Source.Git.Ref, branch},
|
"Assert buildconfig source git Ref": {bc.Spec.CommonSpec.Source.Git.Ref, branch},
|
||||||
"Assert buildconfig source context dir": {bc.Spec.CommonSpec.Source.ContextDir, "a/build"},
|
"Assert buildconfig source context dir": {bc.Spec.CommonSpec.Source.ContextDir, "a/build"},
|
||||||
"Assert buildconfig output name": {bc.Spec.CommonSpec.Output.To.Name, serviceName + ":latest"},
|
"Assert buildconfig output name": {bc.Spec.CommonSpec.Output.To.Name, serviceName + ":latest"},
|
||||||
|
"Assert buildconfig dockerfilepath": {bc.Spec.CommonSpec.Strategy.DockerStrategy.DockerfilePath, "Dockerfile-alternate"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, test := range testCases {
|
for name, test := range testCases {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user