From 9466a2e9c52ca8d3ff5cb009aedc4f0b4ec10293 Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Fri, 25 Jun 2021 22:49:38 +0200 Subject: [PATCH 1/6] Revise Docker image build: * 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). --- .../workflows/build_and_test_docker_on_pr.yml | 56 +++++++++++++++++++ .github/workflows/ci-code.yml | 29 ---------- .github/workflows/push_image_to_dockerhub.yml | 51 +++++++++++++++++ 3 files changed, 107 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/build_and_test_docker_on_pr.yml create mode 100644 .github/workflows/push_image_to_dockerhub.yml diff --git a/.github/workflows/build_and_test_docker_on_pr.yml b/.github/workflows/build_and_test_docker_on_pr.yml new file mode 100644 index 0000000000..51b40e19a4 --- /dev/null +++ b/.github/workflows/build_and_test_docker_on_pr.yml @@ -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 with local folder mounted to it. +# 3. Check that postgresql and rabbitmq are running. +# 4. Copy id_rsa file from the docker container to local folder. +# 5. Restart the container and check that the id_rsa file didn't change. + +name: build-and-test-image-from-pull-request + +on: + [pull_request] + +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' diff --git a/.github/workflows/ci-code.yml b/.github/workflows/ci-code.yml index b1dbe7b92f..b032e16d85 100644 --- a/.github/workflows/ci-code.yml +++ b/.github/workflows/ci-code.yml @@ -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' diff --git a/.github/workflows/push_image_to_dockerhub.yml b/.github/workflows/push_image_to_dockerhub.yml new file mode 100644 index 0000000000..9f460ae14c --- /dev/null +++ b/.github/workflows/push_image_to_dockerhub.yml @@ -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*' + +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_PASSWORD }} + - + name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + tags: ${{ steps.meta.outputs.tags }} From 6d514d9a0543f3fadd3cd918f5ed2170453e54bb Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Mon, 28 Jun 2021 09:35:27 +0200 Subject: [PATCH 2/6] Build and test on PR: modify description. --- .github/workflows/build_and_test_docker_on_pr.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_and_test_docker_on_pr.yml b/.github/workflows/build_and_test_docker_on_pr.yml index 51b40e19a4..17b1f7970a 100644 --- a/.github/workflows/build_and_test_docker_on_pr.yml +++ b/.github/workflows/build_and_test_docker_on_pr.yml @@ -2,10 +2,8 @@ # # The steps are: # 1. Build docker image using cached data. -# 2. Start the docker container with local folder mounted to it. -# 3. Check that postgresql and rabbitmq are running. -# 4. Copy id_rsa file from the docker container to local folder. -# 5. Restart the container and check that the id_rsa file didn't change. +# 2. Start the docker container. +# 3. Check that AiiDA is responsive. name: build-and-test-image-from-pull-request From 2569f4a006afd80f9e7d7f04fc88aa1d67db052d Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Mon, 28 Jun 2021 09:37:39 +0200 Subject: [PATCH 3/6] GitHub docker_on_pr action: do not run if changes were in docs folder. --- .github/workflows/build_and_test_docker_on_pr.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test_docker_on_pr.yml b/.github/workflows/build_and_test_docker_on_pr.yml index 17b1f7970a..04677f4571 100644 --- a/.github/workflows/build_and_test_docker_on_pr.yml +++ b/.github/workflows/build_and_test_docker_on_pr.yml @@ -8,7 +8,9 @@ name: build-and-test-image-from-pull-request on: - [pull_request] + pull_request: + path_ignore: + - 'docs/**' jobs: From 6fc6ad5a43890321496349a84d53bf504fd7f67e Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Mon, 28 Jun 2021 10:54:09 +0200 Subject: [PATCH 4/6] fix --- .github/workflows/build_and_test_docker_on_pr.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_and_test_docker_on_pr.yml b/.github/workflows/build_and_test_docker_on_pr.yml index 04677f4571..46cf7f5cd6 100644 --- a/.github/workflows/build_and_test_docker_on_pr.yml +++ b/.github/workflows/build_and_test_docker_on_pr.yml @@ -48,9 +48,9 @@ jobs: - 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' + 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' From 5ccd9851fd6ca5806be4edc7c156a1475a311390 Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Mon, 28 Jun 2021 10:58:48 +0200 Subject: [PATCH 5/6] Rename DOCKER_PASSWORD with DOCKER_TOKEN --- .github/workflows/push_image_to_dockerhub.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_image_to_dockerhub.yml b/.github/workflows/push_image_to_dockerhub.yml index 9f460ae14c..eda9bb0977 100644 --- a/.github/workflows/push_image_to_dockerhub.yml +++ b/.github/workflows/push_image_to_dockerhub.yml @@ -41,7 +41,7 @@ jobs: uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + password: ${{ secrets.DOCKER_TOKEN }} - name: Build and push id: docker_build From 0f77621ca4932ba30cc200624c26e993ed43994e Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Wed, 30 Jun 2021 11:22:07 +0200 Subject: [PATCH 6/6] Update .github/workflows/push_image_to_dockerhub.yml Co-authored-by: Chris Sewell --- .github/workflows/push_image_to_dockerhub.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_image_to_dockerhub.yml b/.github/workflows/push_image_to_dockerhub.yml index eda9bb0977..8ddff0320c 100644 --- a/.github/workflows/push_image_to_dockerhub.yml +++ b/.github/workflows/push_image_to_dockerhub.yml @@ -9,7 +9,7 @@ on: - master - develop tags: - - 'v*' + - "v[0-9]+.[0-9]+.[0-9]+*" jobs: