Skip to content

Commit

Permalink
ansible dockerfile (ansible-lint 6.9.1 using ansible 2.13.6), ansible…
Browse files Browse the repository at this point in the history
… gnu (ansible-lint 6.13.1 using ansible 2.14.1) (#45)
  • Loading branch information
hemnstill authored Mar 3, 2023
1 parent 3e53255 commit 0f7a2d3
Show file tree
Hide file tree
Showing 16 changed files with 229 additions and 12 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ jobs:
workflow: ${{ github.workflow }}
toolset: gnu

ubuntu-docker:
needs: prejob
if: ${{ needs.prejob.outputs.workflow == github.workflow }}
uses: ./.github/workflows/build-docker.yml
with:
workflow: ${{ github.workflow }}

test-ubuntu:
needs: alpine-gnu
uses: ./.github/workflows/test-ubuntu.yml
Expand All @@ -32,14 +39,22 @@ jobs:
workflow: ${{ github.workflow }}
artifact: build-gnu

test-ubuntu-docker:
needs: ubuntu-docker
uses: ./.github/workflows/test-docker.yml
with:
workflow: ${{ github.workflow }}
artifact: build-docker

release:
needs: [test-alpine, test-ubuntu]
needs: [test-alpine, test-ubuntu, test-ubuntu-docker]
uses: ./.github/workflows/release.yml
with:
workflow: ${{ github.workflow }}
tool_version: '7.1.0'
prepare_body: |
bsdtar -Oxf ./build-docker/build-docker.tar.gz build-docker.md >> body.md
bsdtar -Oxf ./build-gnu/build-gnu.tar.gz build-gnu.md >> body.md
artifacts: ./build-gnu/build-gnu.tar.gz
artifacts: ./build-docker/build-docker.tar.gz, ./build-gnu/build-gnu.tar.gz
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
31 changes: 31 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
on:
workflow_call:
inputs:
workflow:
required: true
type: string
toolset:
required: false
type: string
default: 'docker'
version:
required: false
type: string
default: '22.04'

jobs:
build-ubuntu:
runs-on: ubuntu-latest
container: ubuntu:${{ inputs.version }}
steps:
- uses: actions/checkout@v3
- name: build ${{ inputs.workflow }}-ubuntu-${{ inputs.toolset }}
run: |
apt update
apt install -y docker.io
./${{ inputs.workflow }}/build_${{ inputs.toolset }}.sh
- uses: actions/upload-artifact@v3
with:
name: build-${{ inputs.toolset }}
path: ./${{ inputs.workflow }}/release/build-${{ inputs.toolset }}.tar.gz
34 changes: 34 additions & 0 deletions .github/workflows/test-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
workflow_call:
inputs:
workflow:
required: true
type: string
artifact:
required: true
type: string
version:
required: false
type: string
default: 'latest'

jobs:
test-docker:
runs-on: ubuntu-latest
container: ubuntu:${{ inputs.version }}

steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: ${{ inputs.artifact }}
path: .

- name: Test ${{ inputs.artifact }} build on ubuntu:${{ inputs.version }}
run: |
apt update
apt install -y docker.io
tar -xf ./${{ inputs.artifact }}.tar.gz -C ./bin
cd ./${{ inputs.workflow }}
./test_docker.sh
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ bin/
.tmp/

*.tar.gz
*.tar

install-poetry*.py
poetry/poetry-*
poetry/poetry-*

/ansible/Dockerfile
41 changes: 41 additions & 0 deletions ansible/build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
dp0="$(realpath "$(dirname "$0")")"
set -e

alpine_version="3.17.2"
self_name="ansible-alpine-$alpine_version"
image_name="$self_name:latest"

release_version_dirpath="$dp0/release/build"
mkdir -p "$release_version_dirpath"

full_archive_path="$release_version_dirpath/$self_name.tar.gz"

echo "generating Dockerfile ..."
{ printf 'FROM alpine:%s
RUN apk add --no-cache ansible ansible-lint
' "$alpine_version"
} > "$dp0/Dockerfile"

echo "building image '$image_name' ..."
docker build -t "$image_name" "$dp0/."

echo "saving image '$image_name' to '$full_archive_path'"
docker image save "$image_name" | gzip > "$full_archive_path"

cd "$release_version_dirpath"

{ printf '### build-docker.tar.gz
docker image: %s
%s
%s
' "$image_name" \
"$(docker run --rm "$image_name" ansible --version)" \
"$(docker run --rm "$image_name" ansible-lint --version)"
} > build-docker.md

cat build-docker.md

tar -czvf ../build-docker.tar.gz .
26 changes: 23 additions & 3 deletions ansible/build_gnu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export LC_ALL=en_US.UTF-8

tool_name="ansible"
tool_version="7.1.0"
tool_core_version="2.14.1"
tool_lint_version="6.13.1"
python_self_name="python-3.11.1"
self_name="$tool_name-$tool_version"
release_version_dirpath="$dp0/release/$self_name"
echo "::set-output name=tool_name::$tool_name"
echo "::set-output name=tool_version::$tool_version"

mkdir -p "$release_version_dirpath" && cd "$dp0/release"
mkdir -p "$release_version_dirpath/Scripts/bin" && cd "$dp0/release"

echo "download python install script ..."
python_bin_download_url="https://github.com/hemnstill/StandaloneTools/releases/download/$python_self_name/build-gnu.tar.gz"
Expand All @@ -55,28 +57,46 @@ echo "install ansbile ..."
"python3" -m ensurepip
"python3" -m pip install --target="$cpython_lib_path" cffi

"$cpython_bin" -m pip install "ansible-core==$tool_core_version"
"$cpython_bin" -m pip install "$tool_name==$tool_version"
"$cpython_bin" -m pip install "ansible-lint==$tool_lint_version"

echo "prepare build artifacts ..."

cp -f "$dp0/release/ansible.sh" "$release_version_dirpath/"
cp -f "$dp0/release/__main__ansible.py" "$release_version_dirpath/"
cp -f "$dp0/release/_ansible" "$release_version_dirpath/Scripts/bin/ansible"

cp -f "$dp0/release/ansible-config.sh" "$release_version_dirpath/"
cp -f "$dp0/release/__main__ansible-config.py" "$release_version_dirpath/"
cp -f "$dp0/release/_ansible-config" "$release_version_dirpath/Scripts/bin/ansible-config"

cp -f "$dp0/release/ansible-playbook.sh" "$release_version_dirpath/"
cp -f "$dp0/release/__main__ansible-playbook.py" "$release_version_dirpath/"
cp -f "$dp0/release/_ansible-playbook" "$release_version_dirpath/Scripts/bin/ansible-playbook"

cp -f "$dp0/release/ansible-lint.sh" "$release_version_dirpath/"
cp -f "$dp0/release/__main__ansible-lint.py" "$release_version_dirpath/"

echo "creating archive ..."

cd "$release_version_dirpath"

./"$tool_name.sh" --version

{ printf '%s
{ printf '### build-gnu.tar.gz
%s
%s
%s
%s
' "$(./"$tool_name.sh" --version)" \
"$("./ansible-config.sh" --version | head -1)"
"$(./"ansible-config.sh" --version | head -1)" \
"$(./"ansible-playbook.sh" --version | head -1)" \
"$(./"ansible-lint.sh" --version)"
} > build-gnu.md

cat build-gnu.md
Expand Down
7 changes: 7 additions & 0 deletions ansible/release/__main__ansible-lint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
import re
import sys
from ansiblelint.__main__ import _run_cli_entrypoint
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(_run_cli_entrypoint())
7 changes: 7 additions & 0 deletions ansible/release/__main__ansible-playbook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
import re
import sys
from ansible.cli.playbook import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
5 changes: 0 additions & 5 deletions ansible/release/__main__ansible.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# -*- coding: utf-8 -*-
import re
import sys
import os

_current_script_path: str = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(_current_script_path, 'Lib', 'site-packages'))

from ansible.cli.adhoc import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
Expand Down
3 changes: 3 additions & 0 deletions ansible/release/_ansible
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
dp0="$(realpath "$(dirname "$0")")"
"$dp0/python3" "$dp0/../../__main__ansible.py" "$@"
3 changes: 3 additions & 0 deletions ansible/release/_ansible-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
dp0="$(realpath "$(dirname "$0")")"
"$dp0/python3" "$dp0/../../__main__ansible-config.py" "$@"
3 changes: 3 additions & 0 deletions ansible/release/_ansible-playbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
dp0="$(realpath "$(dirname "$0")")"
"$dp0/python3" "$dp0/../../__main__ansible-playbook.py" "$@"
3 changes: 3 additions & 0 deletions ansible/release/ansible-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
dp0="$(realpath "$(dirname "$0")")"
"$dp0/Scripts/bin/python3" "$dp0/__main__ansible-lint.py" "$@"
3 changes: 3 additions & 0 deletions ansible/release/ansible-playbook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
dp0="$(realpath "$(dirname "$0")")"
"$dp0/Scripts/bin/python3" "$dp0/__main__ansible-playbook.py" "$@"
26 changes: 26 additions & 0 deletions ansible/test_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

alpine_version="3.17.2"
self_name="ansible-alpine-$alpine_version"
image_name="$self_name:latest"

docker load --input "../bin/$self_name.tar.gz"

test_version() {
assertEquals "ansible [core 2.13.6]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.10/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.10.10 (main, Feb 9 2023, 02:08:14) [GCC 12.2.1 20220924]
jinja version = 3.1.2
libyaml = True" "$(docker run --rm $image_name ansible --version)"
}

test_ansible_lint_version() {
assertEquals "ansible-lint 6.9.1 using ansible 2.13.6" "$(docker run --rm $image_name ansible-lint --version | head -1)"
}

# Load and run shUnit2.
source "../.tests/shunit2/shunit2"
25 changes: 24 additions & 1 deletion ansible/test_linux.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash

is_alpine_os=false && [[ -f "/etc/alpine-release" ]] && is_alpine_os=true
is_ubuntu_os=false && [[ -f "/etc/lsb-release" ]] && is_ubuntu_os=true

if [[ "$is_alpine_os" == true ]]; then
apk update
apk add --no-cache gcompat
apk add --no-cache gcompat git

{ printf '%s' "-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApZ2u1KJKUu/fW4A25y9m
Expand All @@ -23,6 +25,11 @@ Zvo9GI2e2MaZyo9/lvb+LbLEJZKEQckqRj4P26gmASrZEPStwc+yqy1ShHLA0j6m
export LC_ALL=en_US.UTF-8
fi

if [[ "$is_ubuntu_os" == true ]]; then
apt update
apt install -y git
fi

test_version() {
assertEquals "ansible [core 2.14.1]
config file = None
Expand All @@ -35,5 +42,21 @@ test_version() {
libyaml = True" "$(../bin/ansible.sh --version)"
}

test_bin_version() {
assertEquals "ansible [core 2.14.1]" "$(../bin/Scripts/bin/ansible --version | head -1)"
}

test_ansible_config_version() {
assertEquals "ansible-config [core 2.14.1]" "$(../bin/Scripts/bin/ansible-config --version | head -1)"
}

test_ansible_playbook_version() {
assertEquals "ansible-playbook [core 2.14.1]" "$(../bin/Scripts/bin/ansible-playbook --version | head -1)"
}

test_ansible_lint_version() {
assertEquals "ansible-lint 6.13.1 using ansible 2.14.1" "$(../bin/ansible-lint.sh --version | head -1)"
}

# Load and run shUnit2.
source "../.tests/shunit2/shunit2"

0 comments on commit 0f7a2d3

Please sign in to comment.