Go环境搭建
- root帐户
下载Golang
[root@infra2-test-k8s /]# cd /usr/local/ [root@infra2-test-k8s local]# wget https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz [root@infra2-test-k8s local]# tar -xzvf go1.14.4.linux-amd64.tar.gz
建立Go目录
[root@infra2-test-k8s local]# cd / [root@infra2-test-k8s /]# mkdir go
配置环境变量并设置代理
[root@infra2-test-k8s /]# vim /etc/profile # 添加如下内容: export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin export GOPATH=/go export GO111MODULE=auto export GOPROXY=https://goproxy.cn,direct # 使配置文件生效 [root@infra2-test-k8s /]# source /etc/profile # 校验 [root@infra2-test-k8s /]# go version go version go1.14.4 linux/amd64 [root@infra2-test-k8s /]# go env
Jenkins配置Golang环境
下载Go插件
插件管理可选插件Go
配置Go环境
系统管理>全局工具配置>Go>Go安装
自动安装go1.14.4/usr/local/go
若是出现如下问题:docker
go: command not found
解决办法:apache
[root@infra2-test-k8s bin]# ln -s /usr/local/go/bin/go /usr/bin/
还不行的话则尝试将环境变量配置到jenkins中:vim
GOROOT=/usr/local/go PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/jdk1.8.0_231/bin:/opt/apache-maven-3.6.3/bin:/usr/local/go/bin GOPATH=/go GO111MODULE=on GOPROXY=https://goproxy.cn 路径:系统管理>系统配置>环境变量
Dockerfile
Dockerfilecentos
FROM docker.io/centos:7 ENV PROJECT_DIR=/opt/docker ENV TZ=Asia/Shanghai WORKDIR $PROJECT_DIR COPY src/dataservice/dataservice $PROJECT_DIR/goapp COPY src/dataservice/ipipfree.ipdb $PROJECT_DIR/ipipfree.ipdb COPY src/dataservice/ds.cnf $PROJECT_DIR/ds.cnf COPY src/dataservice/start.sh $PROJECT_DIR/start.sh RUN mkdir /opt/logs RUN chown -R daemon:daemon $PROJECT_DIR RUN chown -R daemon:daemon /opt/logs EXPOSE 8080 USER daemon ENTRYPOINT ["sh", "/opt/docker/start.sh", "test"]
start.sh:bash
#!/bin/bash if [[ $1 == 'prod' ]] then sed -i "s/env=.*/env=DS_ONLINE/" ds.cnf else sed -i "s/env=.*/env=DS_DEV/" ds.cnf fi echo "启动应用" ./goapp > ./nohup.out
build.shapp
#!/bin/sh cd src/dataservice/ pwd CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a dataservice.go
由于项目结构是:maven
dataservice ├── pkg ├── build.sh └── src ├── dataservice │ └── dataservice.go │ └── start.sh │ └── ds.cnf └── go.mod
cdsrc/dataservice/build.sh