Я хочу настроить CI / CD для моего проекта. Моя проблема, когда Laravel запускает миграцию, появляются следующие ошибки:
В моем файле gitlab-ci я протестировал localhost, 127.0.0.01 и имя образа (mcr.microsoft.com/mssql/server) в качестве Host для DB-Host и MS SQL -Host. Ни один из них не работает. Я не знаю этого из-за проблем с сетью между docker и gitlab или конфигурацией Dockerfile.
Это мой Dockerfile:
# Set the base image for subsequent instructions
FROM php:7.3
# Update packages
RUN apt-get update
# Install PHP and composer dependencies
RUN apt-get install gnupg -qq git wget curl libmcrypt-dev libjpeg-dev libpng-dev libfreetype6-dev
libbz2-dev libzip-dev
# Clear out the local repository of retrieved package files
RUN apt-get clean
# Install needed extensions
# Here you can install any other extension that you need during the test and deployment process
RUN docker-php-ext-install pdo_mysql zip
# adding custom MS repository
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-
release.list
# install SQL Server drivers
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y unixodbc-dev msodbcsql17
RUN pecl install sqlsrv \
&& docker-php-ext-enable sqlsrv
RUN pecl install pdo_sqlsrv \
&& docker-php-ext-enable pdo_sqlsrv
RUN echo "extension= pdo_sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
RUN echo "extension= sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
# Install Composer
RUN curl --silent --show-error https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Install Laravel Envoy
RUN composer global require "laravel/envoy=~1.0"
.gitlab-ci.yaml:
image: registry.gitlab.com/mycompany/myRegisteryContainer
services:
- mcr.microsoft.com/mssql/server:2019-latest
variables:
MSSQL_HOST: 127.0.0.1
MSSQL_PID: Developer
ACCEPT_EULA: Y
SA_PASSWORD: myStrongPassword
DB_CONNECTION: sqlsrv
DB_PORT: 1433
DB_HOST : 127.0.0.1
DB_DATABASE: dbname
DB_USERNAME: dbuser
DB_PASSWORD: dbpassword
stages:
- test
- deploy-prod
unit_test:
stage: test
script:
- cp .env.example .env
- composer install
- php artisan key:generate
- php artisan migrate
- vendor/bin/phpunit
deploy_production:
stage: deploy-prod
script:
- "which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )"
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- ~/.composer/vendor/bin/envoy run deploy-prod --commit="$CI_COMMIT_SHA"
environment:
name: production
url: https://api.mywebsite.com
when: manual
only:
- master