Skip to content

Commit

Permalink
Bump
Browse files Browse the repository at this point in the history
  • Loading branch information
bbaassssiiee committed Dec 4, 2022
1 parent 6159f30 commit dcbbc5b
Show file tree
Hide file tree
Showing 25 changed files with 455 additions and 380 deletions.
4 changes: 4 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
skip_list:
- experimental # all rules tagged as experimental
- fqcn-builtins
8 changes: 4 additions & 4 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: "${{ github.repository }}"
- name: molecule
uses: robertdebock/molecule-action@2.6.8
uses: robertdebock/molecule-action@2.7.2
with:
command: lint
test:
Expand All @@ -27,11 +27,11 @@ jobs:
fail-fast: false
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: "${{ github.repository }}"
- name: molecule
uses: robertdebock/molecule-action@2.6.8
uses: robertdebock/molecule-action@2.7.2
with:
image: ${{ matrix.config.image }}
tag: ${{ matrix.config.tag }}
17 changes: 0 additions & 17 deletions .later.yml

This file was deleted.

43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
# https://pre-commit.com/hooks.html
exclude: .venv
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: detect-private-key
- id: end-of-file-fixer
- id: forbid-new-submodules
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/adrienverge/yamllint
rev: v1.26.0
hooks:
- id: yamllint
args: [-c=.yamllint]

- repo: https://github.com/robertdebock/pre-commit
rev: v1.2.2
hooks:
- id: ansible_role_find_unused_variable
- id: ansible_role_find_empty_files
- id: ansible_role_find_empty_directories

- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v2.0.0
hooks:
- id: autopep8

- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
15 changes: 0 additions & 15 deletions .release-it.json

This file was deleted.

4 changes: 2 additions & 2 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ extends: default

rules:
truthy:
allowed-values: ['true', 'false', 'on']
check-keys: true
allowed-values: ['true', 'false']
check-keys: false

ignore: |
.tox/
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

../base:
python3 -m venv ../base
# (source ../base/bin/activate && python3 -m pip install --upgrade pip)
(source ../base/bin/activate && python3 -m pip install --upgrade pip)
(source ../base/bin/activate && pip3 install -r requirements.txt)
(source ../base/bin/activate && mol test)
(source ../base/bin/activate && molecule test)
(source ../base/bin/activate && pre-commit install)
(source ../base/bin/activate && pre-commit run --all-files)


clean:
rm -rf ../base
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Galaxy](https://img.shields.io/badge/galaxy-dockpack.base__goss-blue.svg?style=flat)](https://galaxy.ansible.com/dockpack/base_goss)[![Build Status](https://api.travis-ci.org/dockpack/base_goss.svg)](https://travis-ci.org/dockpack/base_goss)
[![Galaxy](https://img.shields.io/badge/galaxy-dockpack.base__goss-blue.svg?style=flat)](https://galaxy.ansible.com/dockpack/base_goss)

base_goss
---------
Expand All @@ -21,9 +21,9 @@ Role Variables
goss_path: "/usr/bin/"
goss_arch: amd64
goss_dst: /usr/bin/goss
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
goss_test_directory: /root
goss_test_directory_mode: 0700
goss_url: "https://github.com/goss-org/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
goss_test_directory: /etc/goss.d
goss_test_directory_mode: 0755
goss_user: root
goss_install_dgoss: true
goss_download: localhost # also supports 'direct'
Expand Down
10 changes: 6 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
# defaults file for install_goss
# Standards: 0.2
goss_version: "v0.3.18"
goss_path: "/usr/bin/"
desired_state: present
verify_state: false
goss_version: "v0.3.20"
goss_path: "/usr/bin"
goss_arch: amd64
goss_dst: /usr/bin/goss
# yamllint disable-line rule:line-length
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
goss_test_directory: /root
goss_url: "https://github.com/goss-org/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
goss_test_directory: /etc/goss.d
goss_test_directory_mode: 0700
goss_format: tap
goss_user: root
Expand Down
78 changes: 53 additions & 25 deletions files/dgoss
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,74 @@ set -e
USAGE="USAGE: $(basename "$0") [run|edit] <docker_run_params>"
GOSS_FILES_PATH="${GOSS_FILES_PATH:-.}"

info() { echo -e "INFO: $*"; }
error() { echo -e "ERROR: $*";exit 1; }
# Container runtime
CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-docker}"

info() {
echo -e "INFO: $*" >&2;
}
error() {
echo -e "ERROR: $*" >&2;
exit 1;
}

cleanup() {
set +e
{ kill "$log_pid" && wait "$log_pid"; } 2> /dev/null
if [ -n "$CONTAINER_LOG_OUTPUT" ]; then
cp "$tmp_dir/docker_output.log" "$CONTAINER_LOG_OUTPUT"
fi
rm -rf "$tmp_dir"
if [[ $id ]];then
info "Deleting container"
docker rm -vf "$id" > /dev/null
$CONTAINER_RUNTIME rm -vf "$id" > /dev/null
fi
}

run(){
# Copy in goss
cp "${GOSS_PATH}" "$tmp_dir/goss"
chmod 755 "$tmp_dir/goss"
[[ -e "${GOSS_FILES_PATH}/goss.yaml" ]] && cp "${GOSS_FILES_PATH}/goss.yaml" "$tmp_dir"
[[ -e "${GOSS_FILES_PATH}/goss_wait.yaml" ]] && cp "${GOSS_FILES_PATH}/goss_wait.yaml" "$tmp_dir"
[[ ! -z "${GOSS_VARS}" ]] && [[ -e "${GOSS_FILES_PATH}/${GOSS_VARS}" ]] && cp "${GOSS_FILES_PATH}/${GOSS_VARS}" "$tmp_dir"
[[ -e "${GOSS_FILES_PATH}/${GOSS_FILE:-goss.yaml}" ]] && cp "${GOSS_FILES_PATH}/${GOSS_FILE:-goss.yaml}" "$tmp_dir/goss.yaml" && chmod 644 "$tmp_dir/goss.yaml"
[[ -e "${GOSS_FILES_PATH}/goss_wait.yaml" ]] && cp "${GOSS_FILES_PATH}/goss_wait.yaml" "$tmp_dir" && chmod 644 "$tmp_dir/goss_wait.yaml"
[[ ! -z "${GOSS_VARS}" ]] && [[ -e "${GOSS_FILES_PATH}/${GOSS_VARS}" ]] && cp "${GOSS_FILES_PATH}/${GOSS_VARS}" "$tmp_dir" && chmod 644 "$tmp_dir/${GOSS_VARS}"

# Switch between mount or cp files strategy
GOSS_FILES_STRATEGY=${GOSS_FILES_STRATEGY:="mount"}
case "$GOSS_FILES_STRATEGY" in
mount)
info "Starting docker container"
id=$(docker run -d -v "$tmp_dir:/goss" "${@:2}")
docker logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 &
info "Starting $CONTAINER_RUNTIME container"
if [ "$CONTAINER_RUNTIME" == "podman" -a $# == 2 ]; then
id=$($CONTAINER_RUNTIME run -d -v "$tmp_dir:/goss:z" "${@:2}" sleep infinity)
else
id=$($CONTAINER_RUNTIME run -d -v "$tmp_dir:/goss:z" "${@:2}")
fi
;;
cp)
info "Creating docker container"
id=$(docker create "${@:2}")
info "Creating $CONTAINER_RUNTIME container"
id=$($CONTAINER_RUNTIME create "${@:2}")
info "Copy goss files into container"
docker cp $tmp_dir $id:/goss
info "Starting docker container"
docker start $id > /dev/null
$CONTAINER_RUNTIME cp $tmp_dir/. $id:/goss
info "Starting $CONTAINER_RUNTIME container"
$CONTAINER_RUNTIME start $id > /dev/null
;;
*) error "Wrong goss files strategy used! Correct options are \"mount\" or \"cp\"."
esac

$CONTAINER_RUNTIME logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 &
log_pid=$!
info "Container ID: ${id:0:8}"
}

get_docker_file() {
if docker exec "$id" sh -c "test -e $1" > /dev/null;then
local cid=$1 # Docker container ID
local src=$2 # Source file path (in the container)
local dst=$3 # Destination file path

if $CONTAINER_RUNTIME exec "${cid}" sh -c "test -e ${src}" > /dev/null; then
mkdir -p "${GOSS_FILES_PATH}"
info "Copied '$1' from container to '${GOSS_FILES_PATH}'"
docker cp "$id:$1" "${GOSS_FILES_PATH}"
$CONTAINER_RUNTIME cp "${cid}:${src}" "${dst}"
info "Copied '${src}' from container to '${dst}'"
fi
}

Expand All @@ -68,36 +87,45 @@ GOSS_PATH="${GOSS_PATH:-$(which goss 2> /dev/null || true)}"
[[ ${GOSS_WAIT_OPTS+x} ]] || GOSS_WAIT_OPTS="-r 30s -s 1s > /dev/null"
GOSS_SLEEP=${GOSS_SLEEP:-0.2}

[[ $CONTAINER_RUNTIME =~ ^(docker|podman)$ ]] || { error "Runtime must be one of docker or podman"; }

case "$1" in
run)
run "$@"
if [[ -e "${GOSS_FILES_PATH}/goss_wait.yaml" ]]; then
info "Found goss_wait.yaml, waiting for it to pass before running tests"
if [[ -z "${GOSS_VARS}" ]]; then
if ! docker exec "$id" sh -c "/goss/goss -g /goss/goss_wait.yaml validate $GOSS_WAIT_OPTS"; then
if ! $CONTAINER_RUNTIME exec "$id" sh -c "/goss/goss -g /goss/goss_wait.yaml validate $GOSS_WAIT_OPTS"; then
$CONTAINER_RUNTIME logs $id >&2
error "goss_wait.yaml never passed"
fi
else
if ! docker exec "$id" sh -c "/goss/goss -g /goss/goss_wait.yaml --vars='/goss/${GOSS_VARS}' validate $GOSS_WAIT_OPTS"; then
if ! $CONTAINER_RUNTIME exec "$id" sh -c "/goss/goss -g /goss/goss_wait.yaml --vars='/goss/${GOSS_VARS}' validate $GOSS_WAIT_OPTS"; then
$CONTAINER_RUNTIME logs $id >&2
error "goss_wait.yaml never passed"
fi
fi
fi
[[ $GOSS_SLEEP ]] && { info "Sleeping for $GOSS_SLEEP"; sleep "$GOSS_SLEEP"; }
info "Container health"
if [ "true" != "$($CONTAINER_RUNTIME inspect -f '{{.State.Running}}' $id)" ]; then
$CONTAINER_RUNTIME logs $id >&2
error "the container failed to start"
fi
info "Running Tests"
if [[ -z "${GOSS_VARS}" ]]; then
docker exec "$id" sh -c "/goss/goss -g /goss/goss.yaml validate $GOSS_OPTS"
$CONTAINER_RUNTIME exec "$id" sh -c "/goss/goss -g /goss/goss.yaml validate $GOSS_OPTS"
else
docker exec "$id" sh -c "/goss/goss -g /goss/goss.yaml --vars='/goss/${GOSS_VARS}' validate $GOSS_OPTS"
$CONTAINER_RUNTIME exec "$id" sh -c "/goss/goss -g /goss/goss.yaml --vars='/goss/${GOSS_VARS}' validate $GOSS_OPTS"
fi
;;
edit)
run "$@"
info "Run goss add/autoadd to add resources"
docker exec -it "$id" sh -c 'cd /goss; PATH="/goss:$PATH" exec sh'
get_docker_file "/goss/goss.yaml"
get_docker_file "/goss/goss_wait.yaml"
[[ ! -z "${GOSS_VARS}" ]] && get_docker_file "/goss/${GOSS_VARS}"
$CONTAINER_RUNTIME exec -it "$id" sh -c 'cd /goss; PATH="/goss:$PATH" exec sh'
get_docker_file "$id" "/goss/goss.yaml" "${GOSS_FILES_PATH}/${GOSS_FILE:-goss.yaml}"
get_docker_file "$id" "/goss/goss_wait.yaml" "${GOSS_FILES_PATH}/goss_wait.yaml"
[[ ! -z "${GOSS_VARS}" ]] && get_docker_file "$id" "/goss/${GOSS_VARS}" "${GOSS_FILES_PATH}/${GOSS_VARS}"
;;
*)
error "$USAGE"
Expand Down
4 changes: 0 additions & 4 deletions files/goss_render.sh

This file was deleted.

Loading

0 comments on commit dcbbc5b

Please sign in to comment.