Skip to content

Commit 44ab9fc

Browse files
Merge pull request #14 from datastack-net/fix/build-working-dir
fix: building commands outside dockerized working directory
2 parents decf155 + 6cd4701 commit 44ab9fc

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,30 @@ jobs:
4545

4646
- name: Checkout Dockerized
4747
uses: actions/checkout@v2
48+
with:
49+
path: dockerized
4850

49-
- run: bin/dockerized --help
51+
- run: dockerized/bin/dockerized --help
5052
shell: bash
5153

52-
- run: bin/dockerized go version
54+
- run: dockerized/bin/dockerized go version
5355
shell: bash
5456

5557
- name: "Test: version from environment variable"
56-
run: GO_VERSION=1.16.15 bin/dockerized go version | grep "go1.16.15"
58+
run: GO_VERSION=1.16.15 dockerized/bin/dockerized go version | grep "go1.16.15"
5759
shell: bash
5860

5961
- name: "Test: version from dockerized.env"
6062
run: |
6163
mkdir -p project
6264
cd project
6365
echo 'GO_VERSION=1.17.8' > dockerized.env
64-
../bin/dockerized go version | grep "1.17.8"
66+
../dockerized/bin/dockerized go version | grep "1.17.8"
6567
shell: bash
6668

69+
- name: "Test: command that requires building (protoc)"
70+
run: dockerized/bin/dockerized protoc --version
71+
shell: bash
6772

6873
# region windows
6974
- if: runner.os == 'windows'

lib/dockerized.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ func main() {
4949

5050
dockerizedRoot := getDockerizedRoot()
5151
dockerizedDockerComposeFilePath := os.Getenv("COMPOSE_FILE")
52-
if dockerizedDockerComposeFilePath != "" {
53-
if optionVerbose {
54-
fmt.Println("COMPOSE_FILE: ", dockerizedDockerComposeFilePath)
55-
}
56-
} else {
52+
if dockerizedDockerComposeFilePath == "" {
5753
dockerizedDockerComposeFilePath = filepath.Join(dockerizedRoot, "docker-compose.yml")
5854
}
5955

56+
if optionVerbose {
57+
fmt.Println("Dockerized docker-compose file: ", dockerizedDockerComposeFilePath)
58+
}
59+
6060
if commandName == "" || optionHelp {
6161
err := help(dockerizedDockerComposeFilePath)
6262
if err != nil {
@@ -356,6 +356,10 @@ func getBackend() (*api.ServiceProxy, error) {
356356

357357
func dockerComposeBuild(dockerComposeFilePath string, buildOptions api.BuildOptions) error {
358358
project, err := getProject(dockerComposeFilePath)
359+
err = os.Chdir(project.WorkingDir)
360+
if err != nil {
361+
return err
362+
}
359363
if err != nil {
360364
return err
361365
}
@@ -369,6 +373,10 @@ func dockerComposeBuild(dockerComposeFilePath string, buildOptions api.BuildOpti
369373
}
370374

371375
func dockerComposeRun(project *types.Project, runOptions api.RunOptions, volumes []types.ServiceVolumeConfig) error {
376+
err := os.Chdir(project.WorkingDir)
377+
if err != nil {
378+
return err
379+
}
372380
ctx, _ := newSigContext()
373381

374382
serviceName := runOptions.Service

0 commit comments

Comments
 (0)