简体   繁体   English

Apache项目的Gitlab CI

[英]Gitlab CI for apache project

Recently I have started working on Gitlab and as part of learning I have focused on the Gitlab CI process for my future projects.最近我开始在 Gitlab 上工作,作为学习的一部分,我将重点放在 Gitlab CI 流程上,以用于我未来的项目。 I have installed gitlab runner with executor as docker.我已经安装了 gitlab runner 和 executor 作为 docker。 Till here everything is fine.到这里一切都很好。 I have got a website which contains HTML pages and I am deploying it in the default apache web server path (/var/www/html).我有一个包含 HTML 页面的网站,我将其部署在默认的 apache web 服务器路径 (/var/www/html) 中。 Here is the .gitlab-ci.yml file I am using for the build:这是我用于构建的 .gitlab-ci.yml 文件:

image: centos:7

test:app:
 script:
   - yum install -y httpd git ssh
   - cp -R HTML/* /var/www/html/

Till here the build is getting properly but in order to make the apache up and run the test I am unable to do it.到这里为止,构建正在正常进行,但是为了使 apache 启动并运行测试,我无法做到这一点。 When I add this command in the script, eg:当我在脚本中添加此命令时,例如:

image: centos:7

test:app:
 script:
   - yum install -y httpd git ssh
   - cp -R HTML/* /var/www/html/
   - sudo apachectl start or /usr/sbin/httpd start

...I am getting an error as "Command not found". ...我收到“找不到命令”的错误。

How to make the apache instance up and test?如何制作 apache 实例并进行测试?

Docker containers by default run as root, so there's no need to sudo and I don't believe the centos image from the Docker Hub includes the tool. Docker 容器默认以 root 身份运行,因此无需 sudo,而且我不相信来自 Docker Hub 的 centos 映像包含该工具。

When running a process as a container, you don't launch it via systemd or any of the other init systems, you need to spawn it as a foreground process for docker to attach to.将进程作为容器运行时,您不会通过 systemd 或任何其他 init 系统启动它,您需要将其作为前台进程生成,以便 docker 附加到该进程。 It becomes pid 1, it's the only process launched (no ssh daemon or other processes you may expect), and when it exits or is killed, the container is stopped.它变成 pid 1,它是唯一启动的进程(没有 ssh 守护进程或您可能期望的其他进程),当它退出或被杀死时,容器将停止。 The way to do this with apache according to the repository on Docker Hub where it's already created is the following Dockerfile entry:根据已经创建的 Docker Hub 上的存储库,使用 apache 执行此操作的方法是以下 Dockerfile 条目:

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

This is a very old question, but I guess an answer would not hurt.这是一个非常古老的问题,但我想答案不会受到伤害。

Recently I found out how I can use an apache service in a gitlab-ci-job to serve html files that are eg in your repository.最近,我发现了如何在 gitlab-ci-job 中使用 apache 服务来提供存储库中的 html 文件。 The trick is to enable FF_NETWORK_PER_BUILD in your gitlab-ci-file, and to use a custom docker container for the apache server, so that it looks in the builds-directory for the files it needs to serve.诀窍是在您的 gitlab-ci-file 中启用FF_NETWORK_PER_BUILD ,并为 apache 服务器使用自定义 docker 容器,以便它在 builds-directory 中查找它需要服务的文件。

I wrote a blog post on this: Running apache and php-fpm as services in a gitlab-ci job , with all the details.我为此写了一篇博文: Running apache and php-fpm as services in a gitlab-ci job ,包含所有细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM