From 8664dfb12faa93e9096b0f092e631e8c9e1c09ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20=C3=81lvaro?= Date: Sun, 7 Jun 2020 12:19:10 +0200 Subject: [PATCH] feat: Add github actions workflow for PR --- .github/workflows/build-and-test.yml | 79 ++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .github/workflows/build-and-test.yml diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 00000000..2d8496c6 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,79 @@ +name: Build and test + +on: + pull_request: + branches: + - master + +env: + REGISTRY: docker.io + IMAGE_NAME: cdalvaro/saltstack-master + IMAGE_TAG: ci + GITHUB_REF_NAME: ${{ github.event.release.tag_name }} + +jobs: + build: + name: Build Docker image + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - name: Set env variables + run: | + echo ::set-env name=CACHE_FROM::"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" + echo ::set-env name=DOCKER_IMAGE::"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}" + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Cache lastest image + run: docker pull ${CACHE_FROM} + + - name: Build Docker image + run: | + docker build \ + --build-arg VCS_REF=${GITHUB_REF_NAME:-${GITHUB_SHA}} \ + --build-arg BUILD_DATE="$(date +"%Y-%m-%d %H:%M:%S%:z")" \ + --cache-from ${CACHE_FROM} \ + --tag ${DOCKER_IMAGE} . + + - name: Save docker image + run: | + mkdir -p docker/ + docker save -o docker/docker-image.tar ${DOCKER_IMAGE} + + - name: Upload image for test job + uses: actions/upload-artifact@v2 + with: + name: docker-image + path: docker/docker-image.tar + + test: + name: Test Docker image + needs: build + runs-on: ubuntu-latest + env: + CONTAINER_NAME: salt_master_ci + steps: + - name: Download docker image from build job + uses: actions/download-artifact@v2 + with: + name: docker-image + path: docker/ + + - name: Load docker image from build job + run: docker load -i docker/docker-image.tar + + - name: Launch docker container + run: docker run --rm -d --name "${CONTAINER_NAME}" "${IMAGE_NAME}:${IMAGE_TAG}" + + - name: Show container info + run: docker container ls + + - name: Wait for salt-master bootup + run: sleep 60 + + - name: Show salt versions + run: docker exec "${CONTAINER_NAME}" salt --versions + + - name: Test image calling healthcheck + run: docker exec "${CONTAINER_NAME}" /usr/local/sbin/healthcheck