CircleCI - 使用附加数据库映像运行构建的 docker 映像测试 - 连接被拒绝

发布于 2025-01-15 19:25:36 字数 1122 浏览 3 评论 0原文

我编写了一个 Circleci 配置,用于创建应用程序的 docker 映像、运行它、运行测试并将其推送到 DockerHub。

但我不知道如何运行需要数据库的测试。

这是我用于运行测试的配置的一部分。


executors:
    docker-executor:
        environment:
            DOCKER_BUILDKIT: "1"
        docker:
            - image: cimg/base:2021.12

jobs:
    run-tests:
        executor: docker-executor
        steps:
            - setup_remote_docker:
                version: 20.10.7
                docker_layer_caching: true
            - run:
                name: Load archived test image
                command: docker load -i /tmp/workspace/testimage.tar
            - run:
                  name: Start Container
                  command: |
                      docker create --name app_container << pipeline.parameters.app_image >>:testing
                      docker start app_container
            - run:
                  name: Run Tests
                  command: |
                      docker exec -it app_container ./vendor/bin/phpunit --log-junit testresults.xml --colors=never

如何在此处添加 MySQL 服务,以及如何将其与我的应用程序 docker 映像连接,以便我可以运行需要数据库的测试?

I wrote a circleci config for creating docker image of my app, running it, running tests, and pushing it to DockerHub.

But I can't figure out how to run tests that require a database.

Here is part of my config for running tests.


executors:
    docker-executor:
        environment:
            DOCKER_BUILDKIT: "1"
        docker:
            - image: cimg/base:2021.12

jobs:
    run-tests:
        executor: docker-executor
        steps:
            - setup_remote_docker:
                version: 20.10.7
                docker_layer_caching: true
            - run:
                name: Load archived test image
                command: docker load -i /tmp/workspace/testimage.tar
            - run:
                  name: Start Container
                  command: |
                      docker create --name app_container << pipeline.parameters.app_image >>:testing
                      docker start app_container
            - run:
                  name: Run Tests
                  command: |
                      docker exec -it app_container ./vendor/bin/phpunit --log-junit testresults.xml --colors=never

How to add MySQL service here, and how to connect it with my app docker image so I can run tests that require database?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文