Skip to content

Commit

Permalink
fix: [#12] Cannot find Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
sbp-bvanb committed Dec 18, 2024
1 parent 3302238 commit 5437205
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: actions/[email protected]
- uses: schubergphilis/[email protected]
with:
code-coverage-expected: 55.0
code-coverage-expected: 34.5
golang-unit-tests-exclusions: |-
\(cmd\/mcvs-integrationtest-services\)
testing-type: ${{ matrix.testing-type }}
Expand Down
19 changes: 15 additions & 4 deletions internal/oktamock/oktamock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"

"schubergphilis/mcvs-integrationtest-services/internal/pkg/constants"
"schubergphilis/mcvs-integrationtest-services/internal/pkg/dockertestutils"
)

Expand Down Expand Up @@ -45,13 +46,23 @@ func (r *Resource) WithLogger(writer io.Writer) *Resource {
}

// Start starts the resource with given run options.
func (r *Resource) Start(opts *dockertest.RunOptions, contextDir string, hcOpts ...func(*docker.HostConfig)) error {
func (r *Resource) Start(opts *dockertest.RunOptions, _ string, hcOpts ...func(*docker.HostConfig)) error {
opts.Networks = append(opts.Networks, r.network)
var err error
projectRoot, err := constants.FindProjectRoot()
if err != nil {
return fmt.Errorf("failed to determine the root of the project: %w", err)
}
buildArgs := []docker.BuildArg{
{
Name: "APPLICATION",
Value: "oktamock",
},
}
r.resource, err = r.pool.BuildAndRunWithBuildOptions(&dockertest.BuildOptions{
Dockerfile: "./okta/Dockerfile",
ContextDir: contextDir,
BuildArgs: []docker.BuildArg{},
Dockerfile: "./Dockerfile",
ContextDir: projectRoot,
BuildArgs: buildArgs,
}, opts, hcOpts...)
if err != nil {
return fmt.Errorf("unable to build okta mock server container: %w", err)
Expand Down
33 changes: 33 additions & 0 deletions internal/pkg/constants/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package constants

import (
"fmt"
"os"
"path/filepath"
)

func FindProjectRoot() (string, error) {
currentDir, err := os.Getwd()
if err != nil {
return "", err
}

for {
if fileExists(filepath.Join(currentDir, "go.mod")) {
return currentDir, nil
}

parentDir := filepath.Dir(currentDir)
if currentDir == parentDir {
break
}
currentDir = parentDir
}

return "", fmt.Errorf("project root not found")
}

func fileExists(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err)
}

0 comments on commit 5437205

Please sign in to comment.