Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
fix(server): add GOOGLE_CLOUD_REGION to config
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Feb 28, 2024
1 parent 0036294 commit 30d66ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path"

"github.com/reearth/reearthx/log"
"github.com/reearth/reearthx/rerror"
"google.golang.org/api/cloudbuild/v1"
)

Expand Down Expand Up @@ -62,7 +61,7 @@ type CloudBuildConfig struct {
func runCloudBuild(ctx context.Context, conf CloudBuildConfig) error {
cb, err := cloudbuild.NewService(ctx)
if err != nil {
return rerror.ErrInternalBy(err)
return err
}

machineType := ""
Expand All @@ -86,18 +85,14 @@ func runCloudBuild(ctx context.Context, conf CloudBuildConfig) error {
Tags: conf.Tags,
}

if conf.Region != "" {
call := cb.Projects.Locations.Builds.Create(
path.Join("projects", conf.Project, "locations", conf.Region),
build,
)
_, err = call.Do()
} else {
call := cb.Projects.Builds.Create(conf.Project, build)
_, err = call.Do()
}
call := cb.Projects.Locations.Builds.Create(
path.Join("projects", conf.Project, "locations", conf.Region),
build,
)
_, err = call.Do()

if err != nil {
return rerror.ErrInternalBy(err)
return err
}
return nil
}
16 changes: 14 additions & 2 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const configPrefix = "REEARTH_PLATEAUVIEW"
type Config struct {
Port uint `default:"8080" envconfig:"PORT"`
Host string `default:"http://localhost:8080"`
GOOGLE_CLOUD_PROJECT string `envconfig:"GOOGLE_CLOUD_PROJECT" pp:",omitempty"`
GOOGLE_CLOUD_REGION string `envconfig:"GOOGLE_CLOUD_REGION" pp:",omitempty"`
Debug bool `pp:",omitempty"`
Origin []string `pp:",omitempty"`
Secret string `pp:",omitempty"`
Expand Down Expand Up @@ -95,6 +97,16 @@ func (c *Config) Print() string {
}

func (c *Config) CMSIntegration() cmsintegration.Config {
cloudBuildProject := c.Geospatialjp_CloudBuildProject
if cloudBuildProject == "" {
cloudBuildProject = c.GOOGLE_CLOUD_PROJECT
}

cloudBuildRegion := c.Geospatialjp_CloudBuildRegion
if cloudBuildRegion == "" {
cloudBuildRegion = c.GOOGLE_CLOUD_REGION
}

return cmsintegration.Config{
Host: c.Host,
FMEMock: c.FME_Mock,
Expand All @@ -120,8 +132,8 @@ func (c *Config) CMSIntegration() cmsintegration.Config {
GeospatialjpCloudRunJobsJobName: c.Geospatialjp_JobName,
GeospatialjpCloudBuildImage: c.Geospatialjp_CloudBuildImage,
GeospatialjpCloudBuildMachineType: c.Geospatialjp_CloudBuildMachineType,
GeospatialjpCloudBuildProject: c.Geospatialjp_CloudBuildProject,
GeospatialjpCloudBuildRegion: c.Geospatialjp_CloudBuildRegion,
GeospatialjpCloudBuildProject: cloudBuildProject,
GeospatialjpCloudBuildRegion: cloudBuildRegion,
}
}

Expand Down

0 comments on commit 30d66ab

Please sign in to comment.