在sh.yml中编写shell脚本
项目描述
有时GNU make让我感觉老了,shyml让我又感觉回到了婴儿时期。
入门指南
安装
使用 pip install shyml 安装。
可执行文件和shebang
在你的仓库中创建一个可执行yaml文件(按照惯例命名为 sh.yml),shebang中包含shyml,如下所示
#!/usr/bin/env shyml
然后,开始在其中添加YAML文档。
示例
#!/usr/bin/env shyml
name: foo
help: bar
requires:
- other
script:
- ./super
long
line
- shyml_otherjob # call another job as a bash function
---
name: otherjob
script: |
your code here
文档模型
每个YAML文档(由 — 分隔)应包含一个 name 键。
它可以定义的其他键
script: 以列表或字符串格式表示的bash脚本,将代理参数
help: 描述任务的辅助文本
color: 渲染任务名称的颜色
requires: 在执行此任务之前需要执行的其他任务的列表
hook: 设置为 before 以在执行任何其他任务之前自动执行
env: 环境变量的YAML散列
CLI使用
./sh.yml # lists jobs
./sh.yml jobname # run a job in a local bash shell
shell=xonsh ./sh.yml jobname # apparently you your sh.yml contains xonsh instead of bash ^^
./sh.yml debug jobname # print a job script code
./sh.yml test jobname # print a job help
示例
替换tox.ini
因此,shyml最初诞生是因为我想从tox中获得更多功能。具体来说,就是将测试自动化和最终部署(用于集成测试)集中在一个多脚本文件中,以便在各种环境中使用。
在系统Python环境中,即在构建的容器中。
在用户Python环境中,即我在那里检出所有我想要开发的开发源代码,使用我开发的版本(并努力保持与上游一致并具有向前兼容的代码)。
在virtualenv中,以测试已发布的模块版本。
为了解决这个问题,我使用了这样的shyml作业,它会默认使用python3创建venv,如果venv=none则不设置任何venv,如果venv=user则使用用户环境。
---
name: install
help: |
Setup and activate a venv for a python executable
If venv=none, it will not do any venv.
If venv=user, it will use pip install --user.
script: |
if [ "${venv-}" = "user" ]; then
pip_install="pip install --user"
elif [ "${venv-}" != "none" ]; then
export python="${python-python3}"
export path="${path-.venv.$python}"
test -d $path || virtualenv --python=$python $path
set +eux; echo activating $path; source $path/bin/activate; set -eux
fi
${pip_install-pip install} -Ue .[test]
---
name: test
help: Run test in a python3 venv by default.
script: shyml_install && py.test -vv --cov src --strict -r fEsxXw ${@-src}
然后,我可以运行
venv=user ./sh.yml test # in my home
venv=none ./sh.yml test # in a built container
./sh.yml test # just run tests in the default venv tox-like
嵌入docker-compose.yml
---
name: compose
script: |
docker-compose -p $(pwd) -f <(cat <<EOF
version: '3.5'
services:
django:
build:
dockerfile: Dockerfile
context: ./
shm_size: 512mb
depends_on:
- postgres
volumes:
- ./:/app
postgres:
image: postgres:10
EOF
) $@
用buildah替换Dockerfile
---
name: buildah
script:
- buildcntr1=$(buildah from --quiet docker.io/node:10-alpine)
- buildmnt1=$(buildah mount $buildcntr1)
- buildah config
--env DJANGO_SETTINGS_MODULE=mrs.settings
--env UWSGI_MODULE=mrs.wsgi:application
--env NODE_ENV=production
--env PYTHONIOENCODING=UTF-8
--env PYTHONUNBUFFERED=1
--env STATIC_URL=/static/
--env STATIC_ROOT=/app/static
--env UWSGI_SPOOLER_NAMES=mail,stat
--env UWSGI_SPOOLER_MOUNT=/app/spooler
--env VIRTUAL_PROTO=uwsgi
--env LOG=/app/log
--env VIRTUAL_PROTO=uwsgi
--env GIT_COMMIT=$CI_COMMIT_SHA
$buildcntr1
- mkdir -p .cache/{apk,pip,npm}
- buildah run -v $(pwd)/.cache/apk:/root/.cache/apk $buildcntr1
apk add
--update
--cache-dir /root/.cache/apk
ca-certificates
gettext
shadow
python3
py3-pillow
py3-psycopg2
dumb-init
bash
git
curl
uwsgi-python3
uwsgi-http
uwsgi-spooler
uwsgi-cache
uwsgi-router_cache
uwsgi-router_static
- buildah -v $(pwd)/.cache/pip:/root/.cache/pip run $buildcntr1
pip3 install --upgrade pip
- buildah run $buildcntr1
bash -c 'curl -sL https://sentry.io/get-cli/ | bash'
- buildah run $buildcntr1
bash -c 'mkdir -p /app && usermod -d /app -l app node && groupmod -n app node && chown -R app:app /app'
- buildah config --workingdir /app $buildcntr1
- buildah copy $buildcntr1
yarn.lock .babelrc package.json webpack.config.js /app/
- buildah run $buildcntr1
yarn install --frozen-lockfile
- buildah copy $buildcntr1
src/mrs/static /app/src/mrs/static
- buildah run $(pwd)/.cache/npm:/npm $buildcntr1
yarn --cache-folder /npm prepare
- buildah copy $buildcntr1
requirements.txt /app/
- buildah run -v $(pwd)/.cache/pip:/root/.cache/pip $buildcntr1
pip3 install --upgrade -r /app/requirements.txt
- buildah run $buildcntr1 bash
- buildah copy $buildcntr1
setup.py src /app/
- buildah run $buildcntr1 bash
- buildah run -v $(pwd)/.cache/pip:/root/.cache/pip $buildcntr1
pip3 install --editable /app
- buildah run $buildcntr1
mkdir -p /app/{log,static}
- buildah run $buildcntr1
mrs collectstatic --noinput --clear
- buildah copy $buildcntr1
locale /app/locale
- buildah run $buildcntr1
mrs compilemessages -l fr
- buildah run $buildcntr1
'find $STATIC_ROOT -type f | xargs gzip -f -k -9'
项目详情
关闭
shyml-1.0.3.tar.gz的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | d520006ba8b35fa64e31e3932f7b1f0150ad1498f8abce4161778a527fedb66d |
|
| MD5 | 3b90f1486dd0929b6b50636cf28b6c4d |
|
| BLAKE2b-256 | b70115f3b7d4a73390d3fd71cf11a8ffc18ac9327e7919add4c06e10fc6a151e |