Skip to content

Commit

Permalink
Revise Docker image build (#4997).
Browse files Browse the repository at this point in the history
* Build a new image on every PR (with caching).
* Test the functionality of the new image on every PR.
* Build a new image on every commit to develop/master branch and every
time a new tag is created (no caching).

Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com>
  • Loading branch information
yakutovicha and chrisjsewell authored Jun 30, 2021
1 parent f2367e9 commit 9c7ffc2
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 29 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/build_and_test_docker_on_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Test the Docker image on every pull request.
#
# The steps are:
# 1. Build docker image using cached data.
# 2. Start the docker container.
# 3. Check that AiiDA is responsive.

name: build-and-test-image-from-pull-request

on:
pull_request:
path_ignore:
- 'docs/**'

jobs:

build-and-test:

runs-on: ubuntu-latest
timeout-minutes: 30

steps:
-
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
-
name: Build image locally
uses: docker/build-push-action@v2
with:
load: true
push: false
tags: aiida-core:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
-
name: Start and test the container
run: |
export DOCKERID=`docker run -d aiida-core:latest`
docker exec --tty $DOCKERID wait-for-services
docker logs $DOCKERID
docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'verdi profile show default'
docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'verdi computer show localhost'
docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'verdi daemon status'
29 changes: 0 additions & 29 deletions .github/workflows/ci-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,32 +142,3 @@ jobs:
run: |
verdi devel check-load-time
.github/workflows/verdi.sh
docker:
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- uses: actions/checkout@v2

- name: Install docker
run: |
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
- name: Build the aiida-core image
run:
docker build -t aiida-core .

- name: Run aiida-core image and test the default aiida profile and localhost computer.
run: |
export DOCKERID=`docker run -d aiida-core`
docker exec --tty $DOCKERID wait-for-services
docker logs $DOCKERID
docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'verdi profile show default'
docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'verdi computer show localhost'
docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'verdi daemon status'
51 changes: 51 additions & 0 deletions .github/workflows/push_image_to_dockerhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Build the new Docker image on every commit to master/develop branch and on every new tag.
# No caching is involved for the image build. The new image is then pushed to the Docker Hub.

name: build-and-push-to-dockerhub

on:
push:
branches:
- master
- develop
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"

jobs:

build-and-push:

runs-on: ubuntu-latest
timeout-minutes: 30

steps:
-
uses: actions/checkout@v2
-
name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ github.repository }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ steps.meta.outputs.tags }}

0 comments on commit 9c7ffc2

Please sign in to comment.