Skip to content

Commit

Permalink
feat: Add github actions workflow for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
cdalvaro committed Jun 7, 2020
1 parent 2a689ca commit 8664dfb
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8664dfb

Please sign in to comment.