Skip to content

Commit

Permalink
Merge pull request #633 from travis-ci/pd-lxd-arch-override
Browse files Browse the repository at this point in the history
[LXD] Allow arch override to ensure that correct image is selected fo…
  • Loading branch information
pavel-d authored May 7, 2020
2 parents 091e3ff + 8d68a65 commit 941d790
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions backend/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

var (
lxdArchOverride = ""
lxdLimitCPU = "2"
lxdLimitCPUBurst = false
lxdLimitDisk = "10GB"
Expand All @@ -41,9 +42,10 @@ var (
lxdDockerPool = ""
lxdDockerDisk = "10GB"
lxdNetworkIPv6Filtering = "true"
lxdSecurityPrivileged = "false"
lxdSecurityPrivileged = "false"

lxdHelp = map[string]string{
"ARCH_OVERRIDE": fmt.Sprintf("override arch value from job config (default %q)", lxdArchOverride),
"EXEC_CMD": fmt.Sprintf("command to run via exec/ssh (default %q)", lxdExecCmd),
"EXEC_UID": fmt.Sprintf("UID of travis user (default %d)", lxdExecUID),
"MEMORY": fmt.Sprintf("memory to allocate to each container (default %q)", lxdLimitMemory),
Expand All @@ -63,7 +65,7 @@ var (
"NETWORK_STATIC": fmt.Sprintf("whether to statically set network configuration (default %v)", lxdNetworkStatic),
"NETWORK_DNS": fmt.Sprintf("comma separated list of DNS servers (requires NETWORK_STATIC) (default %q)", lxdNetworkDns),
"NETWORK_IPV6_FILTERING": fmt.Sprintf("prevent the containers from spoofing another's IPv6 address (default %s)", lxdNetworkIPv6Filtering),
"SECURITY_PRIVILEGED": fmt.Sprintf("request a container to run without a UID mapping when set true (default %s)", lxdSecurityPrivileged),
"SECURITY_PRIVILEGED": fmt.Sprintf("request a container to run without a UID mapping when set true (default %s)", lxdSecurityPrivileged),
}
)

Expand Down Expand Up @@ -93,9 +95,10 @@ type lxdProvider struct {
limitNetwork string
limitProcess string

image string
runCmd []string
runUID int64
archOverride string
image string
runCmd []string
runUID int64

imageSelectorType string
imageSelector image.Selector
Expand All @@ -110,7 +113,7 @@ type lxdProvider struct {
networkLeases map[string]string
networkLeasesLock sync.Mutex
networkIPv6Filtering string
securityPrivileged string
securityPrivileged string

pool string
dockerCache string
Expand All @@ -126,6 +129,11 @@ func newLXDProvider(cfg *config.ProviderConfig) (Provider, error) {
return nil, err
}

archOverride := lxdArchOverride
if cfg.IsSet("ARCH_OVERRIDE") {
archOverride = cfg.Get("ARCH_OVERRIDE")
}

execCmd := strings.Split(lxdExecCmd, " ")
if cfg.IsSet("EXEC_CMD") {
execCmd = strings.Split(cfg.Get("EXEC_CMD"), " ")
Expand Down Expand Up @@ -307,6 +315,8 @@ func newLXDProvider(cfg *config.ProviderConfig) (Provider, error) {
return &lxdProvider{
client: client,

archOverride: archOverride,

limitCPU: limitCPU,
limitCPUBurst: limitCPUBurst,
limitDisk: limitDisk,
Expand All @@ -330,7 +340,7 @@ func newLXDProvider(cfg *config.ProviderConfig) (Provider, error) {
networkDNS: networkDNS,
networkLeases: networkLeases,
networkIPv6Filtering: networkIPv6Filtering,
securityPrivileged: securityPrivileged,
securityPrivileged: securityPrivileged,

pool: pool,
dockerCache: dockerCache,
Expand Down Expand Up @@ -500,8 +510,13 @@ func (p *lxdProvider) Start(ctx gocontext.Context, startAttributes *StartAttribu
if startAttributes.ImageName != "" {
imageName = startAttributes.ImageName
} else {
imageArch := startAttributes.Arch
if p.archOverride != "" {
imageArch = p.archOverride
}

imageName, err = p.imageSelector.Select(ctx, &image.Params{
Infra: "lxd-" + startAttributes.Arch,
Infra: "lxd-" + imageArch,
Language: startAttributes.Language,
OsxImage: startAttributes.OsxImage,
Dist: startAttributes.Dist,
Expand Down

0 comments on commit 941d790

Please sign in to comment.