Loy*_*eux 5 webserver github docker docker-compose github-actions
我正在开发一个仪表板 Web 应用程序,我想使用 Github 操作来部署和测试它。我已经成功编写了一个工作流程来构建和推送 docker 映像,但在测试它时遇到了问题。
它是一个 Vue 2 应用程序,监听端口 8080,测试是使用 Cypress 执行的。我的工作流程使用 docker-compose 来构建它以用于生产并通过 nginx 提供服务。当然,它适用于我公司服务器上的生产。
通过 Github Actions 部署时,nginx 执行和构建阶段正常运行,应用程序应该启动并运行,但在运行我的测试时,Cypress 在http://127.0.0.1:8080上抛出 ECONNREFUSED上抛出一个 ECONNREFUSED ,就像 github 阻止我一样应用程序侦听此端口或它正在外部容器中运行。
我认为必须有一种方法可以在 Github Actions 上运行和测试 Web 服务器,但我在文档或论坛中找不到它。
有谁知道如何实现这一目标?
这是我的 .yml github 工作流程的注释版本
name: Build and test
# event listener to trigger the workflow
on:
push:
branches:
- 'workflows-dev'
- 'master'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2 # Checkout into the repo
- run: sed -i -e "s/http\:\/\/<STRAPI_URL>/${{ secrets.PREPROD_URL }}/" Dockerfile
- run: docker build -t dashboard:${{ github.run_id }}-test . # Build docker image with a unique tag
- run: docker run dashboard:${{ github.run_id }}-test & # Runs it as a demon job '&'
- run: sleep 60 # Sleeping to let the server actually start up before testing
- run: |
echo {\"site\": \"http://127.0.0.1:8080\", \"identifier\": \"${{ secrets.PREPROD_USER }}\", \"password\": \"${{ secrets.PREPROD_PASSWORD }}\"} > tests/cypress.env.json # Setup ENV variables for the tests
- run: npm test
Run Code Online (Sandbox Code Playgroud)
您应该告诉 docker run公开端口。另外,你为什么用 来分叉 shell &?您可以改为指定该--detach选项。
docker run -p 127.0.0.1:8080:8080 -d dashboard:${{ github.run_id }}-test
Run Code Online (Sandbox Code Playgroud)
为了进一步改进您的 CI,我建议改用 Docker Compose,使用运行状况检查和. 您还可以将构建指令添加到撰写文件和端口侦听配置中。--waitdocker compose up
| 归档时间: |
|
| 查看次数: |
903 次 |
| 最近记录: |