🐳 #296 去掉命名空间
This commit is contained in:
parent
1d42fb1215
commit
a8121d05f8
13
Dockerfile
13
Dockerfile
|
@ -1,13 +0,0 @@
|
||||||
FROM golang:latest
|
|
||||||
MAINTAINER Liang Ding <d@b3log.org>
|
|
||||||
|
|
||||||
ADD . /go/src/github.com/b3log/wide
|
|
||||||
ADD vendor/ /go/src/
|
|
||||||
RUN go install github.com/visualfc/gotools github.com/nsf/gocode github.com/bradfitz/goimports
|
|
||||||
|
|
||||||
RUN useradd wide && useradd runner
|
|
||||||
|
|
||||||
WORKDIR /go/src/github.com/b3log/wide
|
|
||||||
RUN go build -v
|
|
||||||
|
|
||||||
EXPOSE 7070
|
|
12
conf/wide.go
12
conf/wide.go
|
@ -83,16 +83,13 @@ var Wide *conf
|
||||||
// configurations of users.
|
// configurations of users.
|
||||||
var Users []*User
|
var Users []*User
|
||||||
|
|
||||||
// Indicates whether runs via Docker.
|
|
||||||
var Docker bool
|
|
||||||
|
|
||||||
// Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json.
|
// Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json.
|
||||||
func Load(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel,
|
func Load(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel,
|
||||||
confPlayground string, confDocker bool, confUsersWorkspaces string) {
|
confPlayground string, confUsersWorkspaces string) {
|
||||||
// XXX: ugly args list....
|
// XXX: ugly args list....
|
||||||
|
|
||||||
initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel,
|
initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel,
|
||||||
confPlayground, confDocker, confUsersWorkspaces)
|
confPlayground, confUsersWorkspaces)
|
||||||
initUsers()
|
initUsers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +153,7 @@ func initUsers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel,
|
func initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel,
|
||||||
confPlayground string, confDocker bool, confUsersWorkspaces string) {
|
confPlayground string, confUsersWorkspaces string) {
|
||||||
bytes, err := ioutil.ReadFile(confPath)
|
bytes, err := ioutil.ReadFile(confPath)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
|
@ -237,9 +234,6 @@ func initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticSe
|
||||||
Wide.Port = confPort
|
Wide.Port = confPort
|
||||||
}
|
}
|
||||||
|
|
||||||
// Docker flag
|
|
||||||
Docker = confDocker
|
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
Wide.Server = strings.Replace(Wide.Server, "{IP}", Wide.IP, 1)
|
Wide.Server = strings.Replace(Wide.Server, "{IP}", Wide.IP, 1)
|
||||||
Wide.Server = strings.Replace(Wide.Server, "{Port}", Wide.Port, 1)
|
Wide.Server = strings.Replace(Wide.Server, "{Port}", Wide.Port, 1)
|
||||||
|
|
4
main.go
4
main.go
|
@ -57,7 +57,6 @@ func init() {
|
||||||
confContext := flag.String("context", "", "this will overwrite Wide.Context if specified")
|
confContext := flag.String("context", "", "this will overwrite Wide.Context if specified")
|
||||||
confChannel := flag.String("channel", "", "this will overwrite Wide.Channel if specified")
|
confChannel := flag.String("channel", "", "this will overwrite Wide.Channel if specified")
|
||||||
confStat := flag.Bool("stat", false, "whether report statistics periodically")
|
confStat := flag.Bool("stat", false, "whether report statistics periodically")
|
||||||
confDocker := flag.Bool("docker", false, "whether run in a docker container")
|
|
||||||
confPlayground := flag.String("playground", "", "this will overwrite Wide.Playground if specified")
|
confPlayground := flag.String("playground", "", "this will overwrite Wide.Playground if specified")
|
||||||
confUsersWorkspaces := flag.String("users_workspaces", "", "this will overwrite Wide.UsersWorkspaces if specified")
|
confUsersWorkspaces := flag.String("users_workspaces", "", "this will overwrite Wide.UsersWorkspaces if specified")
|
||||||
|
|
||||||
|
@ -75,8 +74,7 @@ func init() {
|
||||||
|
|
||||||
i18n.Load()
|
i18n.Load()
|
||||||
event.Load()
|
event.Load()
|
||||||
conf.Load(*confPath, *confIP, *confPort, *confServer, *confLogLevel, *confStaticServer, *confContext, *confChannel,
|
conf.Load(*confPath, *confIP, *confPort, *confServer, *confLogLevel, *confStaticServer, *confContext, *confChannel, *confPlayground, *confUsersWorkspaces)
|
||||||
*confPlayground, *confDocker, *confUsersWorkspaces)
|
|
||||||
|
|
||||||
conf.FixedTimeCheckEnv()
|
conf.FixedTimeCheckEnv()
|
||||||
session.FixedTimeSave()
|
session.FixedTimeSave()
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
// Copyright (c) 2014-2019, b3log.org & hacpai.com
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build !linux
|
|
||||||
|
|
||||||
package output
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os/exec"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SetNamespace(cmd *exec.Cmd) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
// Copyright (c) 2014-2019, b3log.org & hacpai.com
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package output
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os/exec"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SetNamespace(cmd *exec.Cmd) {
|
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
|
||||||
// cmd.SysProcAttr.Cloneflags = syscall.CLONE_NEWUSER /*| syscall.CLONE_NEWNS*/ | syscall.CLONE_NEWUTS | syscall.CLONE_NEWPID | syscall.CLONE_NEWIPC /*| syscall.CLONE_NEWNET*/
|
|
||||||
cmd.SysProcAttr.Credential = &syscall.Credential{
|
|
||||||
Uid: 1001,
|
|
||||||
Gid: 1001,
|
|
||||||
}
|
|
||||||
|
|
||||||
// cmd.SysProcAttr.UidMappings = []syscall.SysProcIDMap{{ContainerID: 0, HostID: 1001, Size: 1}}
|
|
||||||
// cmd.SysProcAttr.GidMappings = []syscall.SysProcIDMap{{ContainerID: 0, HostID: 1001, Size: 1}}
|
|
||||||
}
|
|
|
@ -24,7 +24,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/b3log/wide/conf"
|
|
||||||
"github.com/b3log/wide/session"
|
"github.com/b3log/wide/session"
|
||||||
"github.com/b3log/wide/util"
|
"github.com/b3log/wide/util"
|
||||||
)
|
)
|
||||||
|
@ -64,10 +63,6 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
cmd := exec.Command(filePath)
|
cmd := exec.Command(filePath)
|
||||||
cmd.Dir = curDir
|
cmd.Dir = curDir
|
||||||
|
|
||||||
if conf.Docker {
|
|
||||||
SetNamespace(cmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/b3log/wide/conf"
|
|
||||||
"github.com/b3log/wide/output"
|
"github.com/b3log/wide/output"
|
||||||
"github.com/b3log/wide/session"
|
"github.com/b3log/wide/session"
|
||||||
"github.com/b3log/wide/util"
|
"github.com/b3log/wide/util"
|
||||||
|
@ -61,10 +60,6 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
cmd := exec.Command(filePath)
|
cmd := exec.Command(filePath)
|
||||||
|
|
||||||
if conf.Docker {
|
|
||||||
output.SetNamespace(cmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
|
|
|
@ -39,7 +39,7 @@ import (
|
||||||
"github.com/b3log/wide/event"
|
"github.com/b3log/wide/event"
|
||||||
"github.com/b3log/wide/log"
|
"github.com/b3log/wide/log"
|
||||||
"github.com/b3log/wide/util"
|
"github.com/b3log/wide/util"
|
||||||
"github.com/go-fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue