Merge pull request #28 from cdalvaro/feat/migrate_from_circleci_to_github_actions

Migrate from CircleCI to GitHub Actions
This commit is contained in:
Carlos D. Álvaro
2020-06-07 18:24:50 +02:00
committed by GitHub
4 changed files with 98 additions and 214 deletions

View File

@@ -1,214 +0,0 @@
version: 2.1
orbs:
docker: circleci/docker@1.0.1
commands:
docker-build:
description: |
Build a Docker image
parameters:
dockerfile:
default: Dockerfile
description: |
Name of dockerfile to use, defaults to Dockerfile
type: string
extra_build_args:
default: ''
description: >
Extra flags to pass to docker build. For examples, see
https://docs.docker.com/engine/reference/commandline/build
type: string
registry:
default: docker.io
description: |
Comma separated list of registry to use, defaults to docker.io
type: string
image:
default: cdalvaro/saltstack-master
description: |
Name of image to build
type: string
tag:
default: ${CIRCLE_SHA1}
description: |
Image tag, defaults to the value of $CIRCLE_SHA1
type: string
path:
default: .
description: |
Path to the directory containing your Dockerfile and build context,
defaults to . (working directory)
type: string
cache_from:
default: ''
description: |
Comma-separated list of images. Images will first be pulled, then passed
as the --cache-from build argument
https://docs.docker.com/engine/reference/commandline/build/
type: string
no_output_timeout:
default: 10m
description: |
No output timeout for build step
type: string
steps:
- when:
condition: <<parameters.cache_from>>
steps:
- run:
name: Build image for <<parameters.registry>>
no_output_timeout: <<parameters.no_output_timeout>>
command: >
echo "<<parameters.cache_from>>" | sed -n 1'p' | tr ',' '\n' |
while read image; do
echo "Pulling ${image} ...";
docker pull "${image}" || true
done
docker_tag_args=""
IFS="," read -ra DOCKER_REGISTRIES \<<< "<<parameters.registry>>"
for registry in "${DOCKER_REGISTRIES[@]}"; do
IFS="," read -ra DOCKER_TAGS \<<< "<<parameters.tag>>"
for tag in "${DOCKER_TAGS[@]}"; do
docker_tag_args="${docker_tag_args} -t ${registry}/<<parameters.image>>:${tag}"
done
done
docker build
<<#parameters.extra_build_args>><<parameters.extra_build_args>><</parameters.extra_build_args>>
\
--cache-from <<parameters.cache_from>> \
-f <<parameters.path>>/<<parameters.dockerfile>> \
${docker_tag_args} \
<<parameters.path>>
- unless:
condition: <<parameters.cache_from>>
steps:
- run:
name: Building image for <<parameters.registry>>
no_output_timeout: <<parameters.no_output_timeout>>
command: >
docker_tag_args=""
IFS="," read -ra DOCKER_REGISTRIES \<<< "<<parameters.registry>>"
for registry in "${DOCKER_REGISTRIES[@]}"; do
IFS="," read -ra DOCKER_TAGS \<<< "<<parameters.tag>>"
for tag in "${DOCKER_TAGS[@]}"; do
docker_tag_args="${docker_tag_args} -t ${registry}/<<parameters.image>>:${tag}"
done
done
docker build
<<#parameters.extra_build_args>><<parameters.extra_build_args>><</parameters.extra_build_args>>
\
-f <<parameters.path>>/<<parameters.dockerfile>> \
${docker_tag_args} \
<<parameters.path>>
docker-save:
description: |
Save one or more images to a tar archive
parameters:
registry:
default: docker.io
description: |
Comma separated list of registry to use, defaults to docker.io
type: string
image:
description: |
Name of image to save
type: string
tag:
default: ${CIRCLE_SHA1}
description: |
Image tag, defaults to the value of $CIRCLE_SHA1
type: string
steps:
- run:
name: Save image to tar archive
command: >
docker_images=""
IFS="," read -ra DOCKER_REGISTRIES \<<< "<<parameters.registry>>"
for registry in "${DOCKER_REGISTRIES[@]}"; do
IFS="," read -ra DOCKER_TAGS \<<< "<<parameters.tag>>"
for tag in "${DOCKER_TAGS[@]}"; do
docker_images="${docker_images} ${registry}/<<parameters.image>>:${tag}"
done
done
mkdir -p ~/docker/
docker save -o ~/docker/docker-images.tar ${docker_images}
- persist_to_workspace:
root: ~/
paths:
- docker
docker-load:
description: |
Load tar archive
steps:
- attach_workspace:
at: ~/
- run:
name: Load images from tar archive
command: >
docker load -i ~/docker/docker-images.tar
jobs:
build:
executor: docker/machine
steps:
- checkout
- docker-build:
registry: docker.io,quay.io
image: cdalvaro/saltstack-master
tag: ${CIRCLE_TAG:-latest}
cache_from: docker.io/cdalvaro/saltstack-master:latest
extra_build_args: '--build-arg VCS_REF=${CIRCLE_TAG:-${CIRCLE_SHA1}} --build-arg BUILD_DATE="$(date +"%Y-%m-%d %H:%M:%S%:z")"'
no_output_timeout: 45m
- docker-save:
registry: docker.io,quay.io
image: cdalvaro/saltstack-master
tag: ${CIRCLE_TAG:-latest}
test:
executor: docker/machine
steps:
- checkout
- docker-load
- run:
name: Launch docker container
command: docker run -it --rm -d --name salt_master cdalvaro/saltstack-master:${CIRCLE_TAG:-latest}
- run:
name: Container info
command: docker container ls
- run:
name: Wait for salt-master bootup
command: sleep 60
- run:
name: Test image bootup
command: docker exec -it salt_master /usr/local/sbin/healthcheck
workflows:
build-and-test:
jobs:
- build:
filters:
tags:
only: /^[0-9._]+$/
- test:
requires:
- build
filters:
tags:
only: /^[0-9._]+$/

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
github: cdalvaro

18
.github/stale.yml vendored Normal file
View File

@@ -0,0 +1,18 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
- keep-alive
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false

79
.github/workflows/build-and-test.yml vendored Normal file
View File

@@ -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