我有一个问题。我开始使用Github Actions,我有一个工作管道,我试图:
1.构建Docker应用程序
1.运行测试
1.发布到Docker存储库
但是测试运行和发布是两个独立的工作,所以我构建了两次映像。
name: Test & Publish Docker Image
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
run_application_tests:
name: Run test suite
runs-on: ubuntu-latest
env:
COMPOSE_FILE: docker-compose.yml
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASS: ${{ secrets.DOCKER_PASS }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login To Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and run docker image
run: docker-compose up -d --build
- name: Run migrations
run: make migrate
- name: Run tests
run: make test
build_and_publish_docker_image:
needs: run_application_tests
name: Build & Publish Docker Images
runs-on: ubuntu-latest
steps:
- name: Checkout The Repo
uses: actions/checkout@v3
- name: Login To Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build & Push Docker Image
uses: docker/build-push-action@v3
with:
push: true
tags: |
me/image:latest
me/image:${{ github.sha }}
Docker映像是一个Ruby-On-Rails应用程序,所以bundle install
需要很长时间。每个构建大约需要2-3分钟。我还尝试添加:
cache-from: type=gha
cache-to: type=gha,mode=max
到docker/build-push-action@v3
,但这导致了:
Error: buildx failed with: ERROR: cache export feature is currently not supported for docker driver. Please switch to a different driver (eg. "docker buildx create --use")
我可以做哪些更改来改进基于时间的渠道?
1条答案
按热度按时间k4ymrczo1#
在作业run_application_tests中,您具有以下代码:
这段代码运行docker-compose为什么?
如果您只想运行测试,那么代码应该是这样的: