-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add github actions workflow for PR
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 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,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 |