mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
Add ability to customize container uid&gid
This commit is contained in:
parent
ed5b820266
commit
b1e9e0d555
2
containerPasswd.txt
Normal file
2
containerPasswd.txt
Normal file
@ -0,0 +1,2 @@
|
||||
root:x:0:0::/w:/bin/bash
|
||||
go-judge:x:1536:1536::/w:/bin/bash
|
||||
7
env/env_linux.go
vendored
7
env/env_linux.go
vendored
@ -17,6 +17,7 @@ const (
|
||||
containerName = "executor_server"
|
||||
defaultWorkDir = "/w"
|
||||
containerCredStart = 10000
|
||||
containerCred = 1000
|
||||
)
|
||||
|
||||
// NewBuilder build a environment builder
|
||||
@ -62,10 +63,14 @@ func NewBuilder(c Config) (pool.EnvBuilder, error) {
|
||||
hostName := containerName
|
||||
domainName := containerName
|
||||
workDir := defaultWorkDir
|
||||
cUID := containerCred
|
||||
cGID := containerCred
|
||||
if mc != nil {
|
||||
hostName = mc.HostName
|
||||
domainName = mc.DomainName
|
||||
workDir = mc.WorkDir
|
||||
cUID = mc.UID
|
||||
cGID = mc.GID
|
||||
}
|
||||
c.Info("Creating container builder: hostName=", hostName, ", domainName=", domainName, ", workDir=", workDir)
|
||||
|
||||
@ -79,6 +84,8 @@ func NewBuilder(c Config) (pool.EnvBuilder, error) {
|
||||
HostName: hostName,
|
||||
DomainName: domainName,
|
||||
WorkDir: workDir,
|
||||
ContainerUID: cUID,
|
||||
ContainerGID: cGID,
|
||||
}
|
||||
cgb := cgroup.NewBuilder(c.CgroupPrefix).WithCPUAcct().WithMemory().WithPids()
|
||||
if c.Cpuset != "" {
|
||||
|
||||
2
env/mount_linux.go
vendored
2
env/mount_linux.go
vendored
@ -25,6 +25,8 @@ type Mounts struct {
|
||||
WorkDir string `yaml:"workDir"`
|
||||
HostName string `yaml:"hostName"`
|
||||
DomainName string `yaml:"domainName"`
|
||||
UID int `yaml:"uid"`
|
||||
GID int `yaml:"gid"`
|
||||
Proc bool `yaml:"proc"`
|
||||
}
|
||||
|
||||
|
||||
@ -47,6 +47,10 @@ mount:
|
||||
- type: tmpfs
|
||||
target: /tmp
|
||||
data: size=16m,nr_inodes=4k
|
||||
# bind a /etc/passed to show customized user name
|
||||
# - type: bind
|
||||
# source: /home/criyle/go-judge/containerPasswd.txt
|
||||
# target: /etc/passwd
|
||||
# java & ghc wants /proc/self/exe
|
||||
proc: true
|
||||
# container work directory
|
||||
@ -55,3 +59,7 @@ workDir: /w
|
||||
hostName: executor_server
|
||||
# container domain name
|
||||
domainName: executor_server
|
||||
# container user uid
|
||||
uid: 1536
|
||||
# container user gid
|
||||
gid: 1536
|
||||
|
||||
Loading…
Reference in New Issue
Block a user