-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docker: run as non-root and use venv * chore: upgrade yamale to v4.0.2 BREAKING CHANGE * feat: rewrite entrypoint for v4 support BREAKING CHANGE * docs: update readme and examples for v4 * chore: remove example files from Docker image
- Loading branch information
Showing
17 changed files
with
183 additions
and
47 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,64 @@ | ||
name: Action tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
branches: | ||
- master | ||
- main | ||
|
||
jobs: | ||
schema: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
test: | ||
# Strict | ||
- suite: nostrict | ||
schema: ./tests/nostrict/schema.yaml | ||
target: ./tests/nostrict/valid-matching-fields.yaml | ||
no-strict: true | ||
error-is-success: false | ||
- suite: nostrict | ||
schema: ./tests/nostrict/schema.yaml | ||
target: ./tests/nostrict/valid-extra-argument.yaml | ||
no-strict: true | ||
error-is-success: false | ||
- suite: nostrict | ||
schema: ./tests/nostrict/schema.yaml | ||
target: ./tests/nostrict/invalid-not-a-boolean.yaml | ||
no-strict: true | ||
error-is-success: true | ||
- suite: nostrict | ||
schema: ./tests/nostrict/schema.yaml | ||
target: ./tests/nostrict/invalid-nums-out-of-range.yaml | ||
no-strict: true | ||
error-is-success: true | ||
|
||
# Nostrict | ||
- suite: strict | ||
schema: ./tests/strict/schema.yaml | ||
target: ./tests/strict/valid-matching-fields.yaml | ||
no-strict: false | ||
error-is-success: false | ||
- suite: strict | ||
schema: ./tests/strict/schema.yaml | ||
target: ./tests/strict/invalid-extra-argument.yaml | ||
no-strict: false | ||
error-is-success: true | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ./ | ||
name: "Test: ${{ matrix.test.suite }} ${{ matrix.test.target }}" | ||
with: | ||
schema: ${{ matrix.test.schema }} | ||
target: ${{ matrix.test.target }} | ||
no-strict: ${{ matrix.test.no-strict }} | ||
error-is-success: ${{ matrix.test.error-is-success }} |
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 |
---|---|---|
@@ -1,16 +1,19 @@ | ||
FROM python:3.8-alpine | ||
FROM alpine:3 | ||
|
||
RUN apk add --no-cache bash | ||
RUN apk add --no-cache bash python3 py3-pip \ | ||
&& mkdir -p /usr/src/app \ | ||
&& addgroup -g 10000 app \ | ||
&& adduser -s /bin/bash -G app -u 10000 -h /usr/src/app -k /dev/null -D app \ | ||
&& python3 -m venv /usr/src/app/venv \ | ||
&& chown -R app:app /usr/src/app | ||
|
||
WORKDIR /usr/src/app | ||
USER 10000:10000 | ||
ENV VIRTUAL_ENV=/usr/src/app/venv \ | ||
PATH=/usr/src/app/venv/bin:$PATH | ||
|
||
COPY requirements.txt ./ | ||
RUN pip install -r requirements.txt | ||
|
||
COPY example/ ./example | ||
|
||
# Nonexistent | ||
USER 2000:2000 | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] |
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
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
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 |
---|---|---|
@@ -1,25 +1,54 @@ | ||
#!/bin/bash | ||
set -eux | ||
|
||
strict='' | ||
schema=${INPUT_SCHEMA:-$1} | ||
target=${INPUT_TARGET:-$2} | ||
# Returns a string `true` the string is considered boolean true, | ||
# otherwise `false`. An empty value is considered false. | ||
function str_bool { | ||
local str="${1:-false}" | ||
local pat='^(true|1|yes)$' | ||
if [[ "$str" =~ $pat ]] | ||
then | ||
echo 'true' | ||
else | ||
echo 'false' | ||
fi | ||
} | ||
|
||
if [ -n "${INPUT_STRICT:-}" ] | ||
then | ||
strict='--strict' | ||
fi | ||
schema="$INPUT_SCHEMA" | ||
target="$INPUT_TARGET" | ||
no_strict=$(str_bool "${INPUT_NO_STRICT:-}") | ||
error_is_success=$(str_bool "${INPUT_ERROR_IS_SUCCESS:-}") | ||
|
||
# Must end with a space here | ||
extra_args=' ' | ||
|
||
if [ ! -e ${schema} ] | ||
if [ ! -e "${schema}" ] | ||
then | ||
>&2 echo "Schema does not exist: $schema" | ||
exit 1 | ||
fi | ||
|
||
if [ ! -e ${target} ] | ||
# TODO: Allow directories | ||
if [ ! -e "${target}" ] | ||
then | ||
>&2 echo "Target does not exist: $target" | ||
exit 1 | ||
fi | ||
|
||
yamale --schema=${schema} $target $strict | ||
if [ "$no_strict" = "true" ] | ||
then | ||
extra_args='--no-strict ' | ||
fi | ||
|
||
if [ "$error_is_success" = "true" ] | ||
then | ||
# Flipped validation logic | ||
echo "--- Flipped validation logic enabled (error-is-success: true)! ---" | ||
# shellcheck disable=SC2086 | ||
yamale $extra_args --schema="${schema}" "$target" && exit 1 | ||
exit 0 | ||
fi | ||
|
||
# Normal execution | ||
# shellcheck disable=SC2086 | ||
yamale $extra_args --schema="${schema}" "$target" |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Bill | ||
age: 26 | ||
height: 6.2 | ||
awesome: "pretty" | ||
age: 42000 | ||
height: "not a number" | ||
awesome: "not a boolean" |
File renamed without changes.
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,4 @@ | ||
name: Bill | ||
age: 26 | ||
height: 6.2 | ||
awesome: True |
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 |
---|---|---|
@@ -1 +1 @@ | ||
yamale~=2.2.0 | ||
yamale~=4.0.2 |
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,4 @@ | ||
name: Bill | ||
age: 26 | ||
height: 6.2 | ||
awesome: "not a boolean" |
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,4 @@ | ||
name: Bill | ||
age: 420 | ||
height: 6.2 | ||
awesome: true |
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,4 @@ | ||
name: str() | ||
age: int(max=200) | ||
height: num() | ||
awesome: bool() |
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,5 @@ | ||
name: Bill | ||
age: 26 | ||
height: 6.2 | ||
awesome: True | ||
extra: true |
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,4 @@ | ||
name: Bill | ||
age: 26 | ||
height: 6.2 | ||
awesome: True |
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,5 @@ | ||
name: Bill | ||
age: 26 | ||
height: 6.2 | ||
awesome: True | ||
extra: true |
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,4 @@ | ||
name: str() | ||
age: int(max=200) | ||
height: num() | ||
awesome: bool() |
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,4 @@ | ||
name: Bill | ||
age: 26 | ||
height: 6.2 | ||
awesome: True |