-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build docker container in GitHub actions
This is a continuation of work done by @eds-collabora in !275 This replaces the old, simpler pipeline with a three phase process: - First, build the image and cache it using docker buildx. - Second, run all the tests in parallel, restoring the image from the cache. - Thirdly, if the tests pass: - if this is a push to the main branch, push to DockerHub. - push to GitHub Container registry (PS: will push to a user's own fork). This uses Buildkit caching aggressively, and will make use of the entire 5GiB allocation of cache space that GitHub provides over time. It requires the following additional repository secrets: - DOCKERHUB_USERNAME: the username to login as on DockerHub (e.g. go-debos) - DOCKERHUB_PASSWORD: an access token for the DockerHub repository. Closes: #275 Based on original work by: Ed Smith <[email protected]> Signed-off-by: Christopher Obbard <[email protected]>
- Loading branch information
1 parent
b324040
commit e4dfbfa
Showing
6 changed files
with
251 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.git |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
name: Build and Test | ||
|
||
env: | ||
GITHUB_TAG: ghcr.io/${{ github.repository }} | ||
DOCKERHUB_TAG: godebos/debos | ||
|
||
on: | ||
- push | ||
- pull_request | ||
- workflow_dispatch | ||
|
||
jobs: | ||
build: | ||
name: Build Docker container | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Repository checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Use cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.build-cache | ||
key: ${{ runner.os }}-docker-${{ github.sha }} | ||
|
||
- name: Build Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: false | ||
file: docker/Dockerfile | ||
cache-to: type=local,dest=/tmp/.build-cache,mode=max | ||
|
||
unit-tests: | ||
name: Run unit tests | ||
needs: | ||
- build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Repository checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Use cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.build-cache | ||
key: ${{ runner.os }}-docker-${{ github.sha }} | ||
|
||
- name: Build Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: false | ||
tags: debos-builder | ||
file: docker/Dockerfile | ||
cache-from: type=local,src=/tmp/.build-cache | ||
load: true | ||
target: builder | ||
|
||
- name: Run unit tests | ||
run: | | ||
docker-compose -f docker/unit-tests.test.yml \ | ||
up --exit-code-from=sut | ||
recipe-tests: | ||
name: Run recipe tests | ||
needs: | ||
- build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Repository checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Use cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.build-cache | ||
key: ${{ runner.os }}-docker-${{ github.sha }} | ||
|
||
- name: Build Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: false | ||
tags: debos | ||
file: docker/Dockerfile | ||
cache-from: type=local,src=/tmp/.build-cache | ||
load: true | ||
|
||
- name: Run test recipes on host | ||
run: | | ||
docker-compose -f docker/recipes.test.yml \ | ||
up --exit-code-from=sut | ||
uml-tests: | ||
name: Run UML tests | ||
needs: | ||
- build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Repository checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Use cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.build-cache | ||
key: ${{ runner.os }}-docker-${{ github.sha }} | ||
|
||
- name: Build Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: false | ||
tags: debos | ||
file: docker/Dockerfile | ||
cache-from: type=local,src=/tmp/.build-cache | ||
load: true | ||
|
||
- name: Run test recipes using UML backend | ||
run: | | ||
docker-compose -f docker/recipes-test-uml.yml \ | ||
up --exit-code-from=sut | ||
publish-github: | ||
name: Publish to GHCR | ||
needs: | ||
- unit-tests | ||
- recipe-tests | ||
- uml-tests | ||
if: github.event_name != 'pull_request' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ${{ env.GITHUB_TAG }} | ||
tags: | | ||
"type=ref,event=branch" | ||
"type=ref,suffix=-{{sha}},event=branch" | ||
"type=ref,suffix=-{{date 'YYYYMMDD'}},event=branch" | ||
"type=ref,event=tag" | ||
"type=ref,event=pr" | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Use cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.build-cache | ||
key: ${{ runner.os }}-docker-${{ github.sha }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
file: docker/Dockerfile | ||
cache-from: type=local,src=/tmp/.build-cache | ||
|
||
publish-dockerhub: | ||
name: Publish to DockerHub | ||
needs: | ||
- unit-tests | ||
- recipe-tests | ||
- uml-tests | ||
if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ${{ env.DOCKERHUB_TAG }} | ||
tags: | | ||
"type=ref,event=branch" | ||
"type=ref,suffix=-{{sha}},event=branch" | ||
"type=ref,suffix=-{{date 'YYYYMMDD'}},event=branch" | ||
"type=ref,event=tag" | ||
"type=ref,event=pr" | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
continue-on-error: true | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Use cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.build-cache | ||
key: ${{ runner.os }}-docker-${{ github.sha }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v2 | ||
continue-on-error: true | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
file: docker/Dockerfile | ||
cache-from: type=local,src=/tmp/.build-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters