摘要:我只想在gitlab-ci中运行一个nginx反向代理,它将映射到我开始使用docker-compose up的容器,以便我可以在我的应用程序上自动运行E2E测试。
因此,我有一个具有3个服务的应用程序:1个DB,1个Node API和1个Nginx服务器,用于提供角度静态文件。
在生产中,这些服务位于nginx反向代理后面。
我希望能够在与生产非常相似的环境中运行端到端测试。 因此,我创建了一个基础图像来运行我的持续集成测试,如下所示:
FROM alpine:latest
# Use edge packages
RUN sed -i -e 's/v[[:digit:]]\.[[:digit:]]/edge/g' /etc/apk/repositories
RUN apk upgrade --update-cache --available
RUN apk update
RUN apk add npm
RUN apk add docker
RUN apk add py-pip
RUN pip install --upgrade pip
RUN pip install docker-compose
RUN apk add openrc --no-cache
RUN rc-update add docker boot
RUN npm install -g @angular/cli
RUN npm install -g protractor
# chromium dependencies
RUN apk add openjdk8-jre-base
RUN apk add nss
RUN apk add chromium-chromedriver
RUN apk add chromium
RUN apk upgrade --no-cache --available
ENV CHROME_BIN /usr/bin/chromium-browser
# netcat to test for docker-compose up
RUN apk add netcat-openbsd
# add netstat to get listening ports
RUN apk add net-tools
## Install nginx to run as reverse proxy
RUN apk add nginx
RUN rc-update add nginx boot
# Add nginx conf
COPY ./proxy.crt /etc/nginx/proxy.crt
COPY ./proxy.key /etc/nginx/proxy.key
COPY ./nginx.conf /etc/nginx/nginx.conf
我的gitlab-ci.yml:
image: registry.gitlab.com/ldso18-19/t2g2/base_ci:1.0
services:
- docker:dind
stages:
- build
- test
- release
- deploy
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
WEB_TEST_IMAGE: registry.gitlab.com/ldso18-19/t2g2/web:$CI_COMMIT_REF_SLUG
API_TEST_IMAGE: registry.gitlab.com/ldso18-19/t2g2/api:$CI_COMMIT_REF_SLUG
DB_TEST_IMAGE: registry.gitlab.com/ldso18-19/t2g2/db:$CI_COMMIT_REF_SLUG
WEB_RELEASE_IMAGE: registry.gitlab.com/ldso18-19/t2g2/web:latest
API_RELEASE_IMAGE: registry.gitlab.com/ldso18-19/t2g2/api:latest
DB_RELEASE_IMAGE: registry.gitlab.com/ldso18-19/t2g2/db:latest
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
web_integration_tests:
stage: test
script:
- rc-status
- nginx -t
- /etc/init.d/nginx start
- netstat -l
- docker-compose pull
- docker-compose up -d
- cd web/e2e
- sleep 10
- netstat -l
- protractor prod-conf.js
我的nginx.conf文件:
user nginx;
worker_processes 1;
pid /var/run/nginx.pid;
events {}
http {
include /etc/nginx/mime.types;
# enable reverse proxy
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_ssl_session_reuse off;
server {
server_name localhost;
listen 443 ssl;
listen [::]:443 ssl ipv6only=on; # managed by Certbot
ssl_certificate /etc/nginx/proxy.crt; # managed by Certbot
ssl_certificate_key /etc/nginx/proxy.key; # managed by Certbot
ssl_session_cache shared:le_nginx_SSL:1m;
ssl_session_timeout 1440m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS";
# Reverse Proxying (ineeve)
location / {
proxy_pass https://docker:4200;
}
location /api/ {
proxy_pass https://docker:8443/;
}
}
}
daemon off;
我的docker-compose文件:
version: '3.7'
services:
web:
image: registry.gitlab.com/project_name/web:42-ci
ports:
- 4200:4200
depends_on:
- api
db:
image: registry.gitlab.com/project_name/db:42-ci
ports:
- 5433:5432
volumes:
- postgres:/var/lib/postgresql/data
api:
image: registry.gitlab.com/project_name/api:42-ci
depends_on:
- db
ports:
- 8443:8443
volumes:
postgres:
问题:当gitlab-ci运行时,出现以下错误:
$ rc-status
Service `hwdrivers' needs non existent service `dev'
* Caching service dependencies ... [ ok ]
Runlevel: sysinit
Dynamic Runlevel: hotplugged
Dynamic Runlevel: needed/wanted
Dynamic Runlevel: manual
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$ /etc/init.d/nginx start
* You are attempting to run an openrc service on a
* system which openrc did not boot.
* You may be inside a chroot or you may have used
* another initialization system to boot this system.
* In this situation, you will get unpredictable results!
* If you really want to do this, issue the following command:
* touch /run/openrc/softlevel
* ERROR: networking failed to start
* ERROR: cannot start nginx as networking would not start
任何帮助将不胜感激,因为我花了近10个小时尝试不同的配置。