Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set group permissions in volumes #281

Merged
merged 8 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/blockchain/ethereum/connector/ethconnect/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (e *Ethconnect) GenerateConfig(stack *types.Stack, member *types.Organizati
RPC: &RPC{URL: fmt.Sprintf("http://%s:8545", blockchainServiceName)},
OpenAPI: &OpenAPI{
EventPollingIntervalSec: 1,
StoragePath: "./abis",
EventsDB: "./events",
StoragePath: "./data/abis",
EventsDB: "./data/events",
},
HTTP: &HTTP{
Port: 8080,
Expand Down
6 changes: 2 additions & 4 deletions internal/blockchain/ethereum/connector/ethconnect/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ func (e *Ethconnect) GetServiceDefinitions(s *types.Stack, dependentServices map
Ports: []string{fmt.Sprintf("%d:8080", member.ExposedConnectorPort)},
Volumes: []string{
fmt.Sprintf("ethconnect_config_%s:/ethconnect/config", member.ID),
fmt.Sprintf("ethconnect_abis_%s:/ethconnect/abis", member.ID),
fmt.Sprintf("ethconnect_events_%s:/ethconnect/events", member.ID),
fmt.Sprintf("ethconnect_data_%s:/ethconnect/data", member.ID),
},
Logging: docker.StandardLogOptions,
},
VolumeNames: []string{
fmt.Sprintf("ethconnect_config_%v", member.ID),
fmt.Sprintf("ethconnect_abis_%v", member.ID),
fmt.Sprintf("ethconnect_events_%v", member.ID),
fmt.Sprintf("ethconnect_data_%v", member.ID),
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (e *Evmconnect) GenerateConfig(stack *types.Stack, org *types.Organization,
},
Persistence: &PersistenceConfig{
LevelDB: &LevelDBConfig{
Path: "/evmconnect/leveldb",
Path: "/evmconnect/data/leveldb",
},
},
FFCore: &FFCoreConfig{
Expand Down
9 changes: 4 additions & 5 deletions internal/blockchain/ethereum/connector/evmconnect/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ func (e *Evmconnect) GetServiceDefinitions(s *types.Stack, dependentServices map
Service: &docker.Service{
Image: s.VersionManifest.Evmconnect.GetDockerImageString(),
ContainerName: fmt.Sprintf("%s_evmconnect_%v", s.Name, i),
Command: "-f /evmconnect/config/config.yaml",
Command: "-f /evmconnect/config.yaml",
DependsOn: dependsOn,
Ports: []string{fmt.Sprintf("%d:%v", member.ExposedConnectorPort, e.Port())},
Volumes: []string{
fmt.Sprintf("evmconnect_config_%s:/evmconnect/config", member.ID),
fmt.Sprintf("evmconnect_leveldb_%s:/evmconnect/leveldb", member.ID),
fmt.Sprintf("%s/config/evmconnect_%s.yaml:/evmconnect/config.yaml", s.RuntimeDir, member.ID),
fmt.Sprintf("evmconnect_data_%s:/evmconnect/data", member.ID),
},
Logging: docker.StandardLogOptions,
},
VolumeNames: []string{
fmt.Sprintf("evmconnect_config_%s", member.ID),
fmt.Sprintf("evmconnect_leveldb_%s", member.ID),
fmt.Sprintf("evmconnect_data_%s", member.ID),
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/blockchain/fabric/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package fabric

var FabricToolsImageName = "hyperledger/fabric-tools:2.3"
var FabricToolsImageName = "hyperledger/fabric-tools:2.5"
var FabricCAImageName = "hyperledger/fabric-ca:1.5"
var FabricOrdererImageName = "hyperledger/fabric-orderer:2.3"
var FabricPeerImageName = "hyperledger/fabric-peer:2.3"
var FabricOrdererImageName = "hyperledger/fabric-orderer:2.5"
var FabricPeerImageName = "hyperledger/fabric-peer:2.5"
1 change: 1 addition & 0 deletions internal/blockchain/fabric/fabric_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (p *FabricProvider) FirstTimeSetup() error {
"run",
"--platform", getDockerPlatform(),
"--rm",
"-e", "FABRIC_CFG_PATH=/etc/hyperledger/fabric/configtx.yaml",
"-v", fmt.Sprintf("%s:/etc/firefly", volumeName),
"-v", fmt.Sprintf("%s:/etc/hyperledger/fabric/configtx.yaml", path.Join(blockchainDirectory, "configtx.yaml")),
FabricToolsImageName,
Expand Down
2 changes: 1 addition & 1 deletion internal/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func getPostgresURL(member *types.Organization) string {

func getSQLitePath(member *types.Organization, runtimeDir string) string {
if !member.External {
return "/etc/firefly/db/sqlite.db?_busy_timeout=5000"
return "/etc/firefly/data/db/sqlite.db?_busy_timeout=5000"
} else {
return path.Join(runtimeDir, member.ID+".db")
}
Expand Down
19 changes: 17 additions & 2 deletions internal/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ func CreateVolume(ctx context.Context, volumeName string) error {

func CopyFileToVolume(ctx context.Context, volumeName string, sourcePath string, destPath string) error {
fileName := path.Base(sourcePath)
return RunDockerCommand(ctx, ".", "run", "--rm", "-v", fmt.Sprintf("%s:/source/%s", sourcePath, fileName), "-v", fmt.Sprintf("%s:/dest", volumeName), "alpine", "cp", "-R", path.Join("/", "source", fileName), path.Join("/", "dest", destPath))
source := path.Join("/", "source", fileName)
dest := path.Join("/", "dest", destPath)
// command := fmt.Sprintf("run --rm -v %s:%s -v %s:%s alpine /bin/sh -c 'cp -R %s %s '", sourcePath, source, volumeName, dest, source, dest, dest, dest)
command := fmt.Sprintf("cp -R %s %s && chgrp -R 0 %s && chmod -R g+rwX %s", source, dest, dest, dest)
return RunDockerCommand(ctx, ".", "run", "--rm", "-v", fmt.Sprintf("%s:%s", sourcePath, source), "-v", fmt.Sprintf("%s:/dest", volumeName), "alpine", "/bin/sh", "-c", command)
}

func MkdirInVolume(ctx context.Context, volumeName string, directory string) error {
return RunDockerCommand(ctx, ".", "run", "--rm", "-v", fmt.Sprintf("%s:/dest", volumeName), "alpine", "mkdir", "-p", path.Join("/", "dest", directory))
dest := path.Join("/", "dest", directory)
command := fmt.Sprintf("mkdir -p %s && chgrp -R 0 %s && chmod -R g+rwX %s", dest, dest, dest)
return RunDockerCommand(ctx, ".", "run", "--rm", "-v", fmt.Sprintf("%s:/dest", volumeName), "alpine", "/bin/sh", "-c", command)
}

func RemoveVolume(ctx context.Context, volumeName string) error {
Expand Down Expand Up @@ -88,6 +94,15 @@ func RunDockerCommand(ctx context.Context, workingDir string, command ...string)
return err
}

func RunDockerCommandLine(ctx context.Context, workingDir string, command string) error {
parsedCommand := strings.Split(command, " ")
fmt.Println(parsedCommand)
dockerCmd := exec.Command("docker", parsedCommand...)
dockerCmd.Dir = workingDir
_, err := runCommand(ctx, dockerCmd)
return err
}

func RunDockerComposeCommand(ctx context.Context, workingDir string, command ...string) error {
switch ctx.Value(CtxComposeVersionKey{}) {
case ComposeV1:
Expand Down
4 changes: 2 additions & 2 deletions internal/docker/docker_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func CreateDockerCompose(s *types.Stack) *DockerComposeConfig {
},
Volumes: []string{
fmt.Sprintf("%s:/etc/firefly/firefly.core.yml:ro", configFile),
fmt.Sprintf("firefly_core_db_%s:/etc/firefly/db", member.ID),
fmt.Sprintf("firefly_core_data_%s:/etc/firefly/data", member.ID),
},
DependsOn: map[string]map[string]string{},
Logging: StandardLogOptions,
}
compose.Volumes[fmt.Sprintf("firefly_core_db_%s", member.ID)] = struct{}{}
compose.Volumes[fmt.Sprintf("firefly_core_data_%s", member.ID)] = struct{}{}
compose.Services["firefly_core_"+member.ID].DependsOn["dataexchange_"+member.ID] = map[string]string{"condition": "service_started"}
compose.Services["firefly_core_"+member.ID].DependsOn["ipfs_"+member.ID] = map[string]string{"condition": "service_healthy"}
}
Expand Down
7 changes: 7 additions & 0 deletions internal/stacks/stack_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ func (s *StackManager) copyDataExchangeConfigToVolumes() error {
// Copy files into docker volumes
memberDXDir := path.Join(configDir, "dataexchange_"+member.ID)
volumeName := fmt.Sprintf("%s_dataexchange_%s", s.Stack.Name, member.ID)
docker.MkdirInVolume(s.ctx, volumeName, "destinations")
docker.MkdirInVolume(s.ctx, volumeName, "peers")
docker.MkdirInVolume(s.ctx, volumeName, "peer-certs")
if err := docker.CopyFileToVolume(s.ctx, volumeName, path.Join(memberDXDir, "config.json"), "/config.json"); err != nil {
return err
Expand Down Expand Up @@ -933,6 +935,11 @@ func (s *StackManager) runFirstTimeSetup(options *types.StartOptions) (messages
}
}
s.patchFireFlyCoreConfigs(configDir, member, newConfig)

// Create data directory with correct permissions inside volume
dataVolumeName := fmt.Sprintf("%s_firefly_core_data_%s", s.Stack.Name, member.ID)
docker.CreateVolume(s.ctx, dataVolumeName)
docker.MkdirInVolume(s.ctx, dataVolumeName, "db")
}

// Re-write the docker-compose config again, in case new values have been added
Expand Down
Loading