【发布时间】:2020-06-26 07:26:59
【问题描述】:
我正在尝试使用 github 操作设置 python 应用程序和 mysql 服务器。这是我的行动:
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
# Label of the container job
container-job:
# Containers must run in Linux based operating systems
runs-on: ubuntu-latest
# Docker Hub image that `container-job` executes in
container: python:3.7
# Service containers to run with `container-job`
services:
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: cloudia_test
MYSQL_USER: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
# Label used to access the service container
redis:
# Docker Hub image
image: redis
ports:
- 6379/tcp
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
# Downloads a copy of the code in your repository before running CI tests
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.7'
- name: pip cache
uses: actions/cache@v2
id: cache
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
# Performs a clean installation of all dependencies in the `package.json` file
# For more information, see https://docs.npmjs.com/cli/ci.html
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Run tests
env:
PYTHON_ENV: test
REDIS_URL: redis://redis
DATABASE_HOST: mysql
DATABASE_PORT: ${{ job.services.mysql.ports[3306] }}
run: |
pytest
但是我收到了这个错误:
value = OperationalError(2002, "Can't connect to MySQL server on 'mysql' (115)")
我尝试将 DATABASE_HOST 用作 127.0.0.1 和 0.0.0.0,但我也收到消息“无法连接到 '127.0.0.1' 上的 MySQL 服务器”或“无法连接到 '0.0 上的 MySQL 服务器” .0.0'"
【问题讨论】:
标签: python mysql github-actions