简体   繁体   中英

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. I have installed gitlab runner with executor as 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). Here is the .gitlab-ci.yml file I am using for the build:

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. 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?

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.

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. 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. The way to do this with apache according to the repository on Docker Hub where it's already created is the following Dockerfile entry:

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. 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.

I wrote a blog post on this: Running apache and php-fpm as services in a gitlab-ci job , with all the details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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