Skip to content

Commit

Permalink
feat: Add ability to override dockerfilePath in tbrc to build differe…
Browse files Browse the repository at this point in the history
…nt version of services
  • Loading branch information
cszatmary committed Apr 1, 2020
1 parent 4d40aa2 commit 11808f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ Override schema:
envVars: map # A list of env vars to set for the service, will be merged with exisiting env vars
preRun: string # Script to run before starting the service
build: # Configuration when building the service locally
command: string # Command to run when the container starts
target: string #
command: string # Command to run when the container starts
dockerfilePath: string # The path to the dockerfile to build the service locally
target: string # The target to build in a multi-stage build
remote: # Configuration when pulling the service from a remote registry
command: string # Command to run when the container starts
enabled: boolean # Whether or not to use remote version
Expand Down
18 changes: 16 additions & 2 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package service
import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/TouchBistro/tb/util"
)
Expand Down Expand Up @@ -85,8 +88,9 @@ func (s Service) DockerName() string {
}

type BuildOverride struct {
Command string `yaml:"command"`
Target string `yaml:"target"`
Command string `yaml:"command"`
DockerfilePath string `yaml:"dockerfilePath"`
Target string `yaml:"target"`
}

type RemoteOverride struct {
Expand Down Expand Up @@ -117,6 +121,16 @@ func (s Service) applyOverride(o ServiceOverride) (Service, error) {
s.Build.Command = o.Build.Command
}

if o.Build.DockerfilePath != "" {
dp := o.Build.DockerfilePath
// Local paths can be prefixed with ~ for convenience
if strings.HasPrefix(dp, "~") {
s.Build.DockerfilePath = filepath.Join(os.Getenv("HOME"), strings.TrimPrefix(dp, "~"))
} else {
s.Build.DockerfilePath = dp
}
}

if o.Build.Target != "" {
s.Build.Target = o.Build.Target
}
Expand Down

0 comments on commit 11808f4

Please sign in to comment.