一、概述

基于 Docker 集成 CI 环境。涉及技术:Linux(Ubuntu 14.04), Docker, Jenkins, Git/Gitlab, Web/Httpbin, Python/Pytest, UI/Selenium, Robotframework, Grid Server, Appium 等。

架构图如下:

Docker CI: 基于 Dockerfile 构建 HttpTestbed 新镜像

二、Docker 平台(Ubuntu 14.04):基于 Dockerfile 构建 HttpTestbed 新镜像

# cd /vm/docker/httptestbed
# sudo docker build -t httptest .

清单

dockerfile

FROM ubuntu:14.04

MAINTAINER Allan <[email protected]>

ENV DEBIAN_FRONTEND noninteractive
ENV USER root

# VNC 配置
RUN apt-get update && \
    apt-get install python-pip -y && \
    apt-get install -y --no-install-recommends ubuntu-desktop && \
    apt-get install -y gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal && \
    apt-get install -y tightvncserver && \
    mkdir /root/.vnc
ADD xstartup /root/.vnc/xstartup
ADD passwd /root/.vnc/passwd
RUN chmod 600 /root/.vnc/passwd

# SSH 配置
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:screencast' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed '[email protected]\s*required\s*[email protected] optional [email protected]' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

# 编辑器
RUN apt-get update && \
    apt-get install vim -y && \
    apt-get install gedit -y

#安装基本字体
RUN apt-get -qqy --no-install-recommends install \
fonts-ipafont-gothic \
xfonts-100dpi \
xfonts-75dpi \
xfonts-cyrillic \
xfonts-scalable

#安装文泉驿微米黑字体
RUN apt-get -qqy install ttf-wqy-microhei \
&& ln -snf /etc/fonts/conf.d/65-wqy-microhei.conf /etc/fonts/conf.d/69-language-selector-zh-cn.conf

# 时区:中国上海
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 配置中文
RUN apt-get install -y locales
RUN locale-gen zh_CN.UTF-8 &&\
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales
RUN locale-gen zh_CN.UTF-8
ENV LANG zh_CN.UTF-8
ENV LANGUAGE zh_CN:zh
ENV LC_ALL zh_CN.UTF-8

RUN sed -i '$a\set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936' /etc/vim/vimrc
RUN sed -i '$a\set encoding=utf-8' /etc/vim/vimrc

# 设置 Java(Jenkins)
RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
RUN add-apt-repository ppa:webupd8team/java
RUN apt-get update
RUN apt-get install openjdk-8-jdk -y
RUN apt-get install oracle-java8-set-default -y

# 安装 Git
RUN apt-get update
RUN apt-get install git -y

# Http Test 库
RUN mkdir /root/.pip
ADD pip.conf /root/.pip/pip.conf
RUN pip install requests
RUN pip install pytest
RUN pip install xlrd
RUN pip install xlwt
RUN pip install natsort

# 工程目录
RUN mkdir /var/project

# 启动 SSH 和 vnc
RUN apt-get install supervisor -y
ADD vnc.sh /root/.vnc/vnc.sh
RUN chmod a+x /root/.vnc/vnc.sh
ADD supervisord.conf /etc/supervisord.conf
ADD start.sh /opt
RUN chmod a+x /opt/start.sh
ENTRYPOINT ["/opt/start.sh"]

EXPOSE 22
EXPOSE 5901

passwd

配置密码

pip.conf

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

xstartup

#!/bin/sh
export XKL_XMODMAP_DISABLE=1
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &

gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
gnome-terminal &

vnc.sh

#!/bin/bash
while [ 1 ]
do
  ps -fe|grep Xvnc |grep -v grep
  if [ $? -ne 0 ]
  then
  echo "start vnc ..."
  rm -f /tmp/.X1-lock
  rm -f /tmp/.X11-unix/X1
  /usr/bin/vncserver :1 -geometry 1280x800 -depth 24
  else
  echo "vnc is running"
  fi
  sleep 30
 done

supervisord.conf

[supervisord]
nodaemon=true

[program:vnc]
command=/root/.vnc/vnc.sh
autorestart=true
priority=200

start.sh

#!/bin/bash
/usr/sbin/sshd -D &
/usr/bin/supervisord -c /etc/supervisord.conf

三、查看并运行 httptestbed 镜像

--name: 容器名
--restart : 自动启动
-d: daemon 守护进程
-p: publlish 端口,5901是 httptest VNC 端口,1022 是 SSH 端口

# sudo docker images
# sudo docker run --name httptest --restart always -d -p 5901:5901 -p 1022:22 httptestbed
# sudo docker ps

四、VNC Viewer 打开容器 httptest

Docker CI: 基于 Dockerfile 构建 HttpTestbed 新镜像
Docker CI: 基于 Dockerfile 构建 HttpTestbed 新镜像
Docker CI: 基于 Dockerfile 构建 HttpTestbed 新镜像

相关文章:

  • 2021-05-19
  • 2022-12-23
  • 2021-09-29
  • 2021-04-26
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
猜你喜欢
  • 2021-10-15
  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
  • 2021-10-22
  • 2022-12-23
  • 2021-05-11
相关资源
相似解决方案