From 85a5dcbff7c66d0e86b15262174dd0f98303e6d8 Mon Sep 17 00:00:00 2001 From: Billy Lynch Date: Tue, 2 Jun 2020 17:42:32 -0400 Subject: [PATCH] Dockerize sync tool. This achieves a few things: 1. Creates Dockerfile for sync tool, so that it can be invoked from Tekton tasks. 2. Makes sync config directory configurable by flag, so that the tool can be ran from any directory. This defaults to sync/config (same as before). Symlinks are retainined in the root directory for requirements.txt and runtime.txt to satisfy Netlify Build requirements: https://docs.netlify.com/configure-builds/manage-dependencies/#python Issue: #34 --- requirements.txt | 6 +----- runtime.txt | 2 +- sync/Dockerfile | 12 ++++++++++++ sync/README.md | 20 +++++++++++++++++--- sync/requirements.txt | 6 ++++++ sync/runtime.txt | 1 + sync/sync.py | 22 +++++++++++++++++----- 7 files changed, 55 insertions(+), 14 deletions(-) mode change 100644 => 120000 requirements.txt mode change 100644 => 120000 runtime.txt create mode 100644 sync/Dockerfile create mode 100644 sync/requirements.txt create mode 100644 sync/runtime.txt diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index ad7b97f1..00000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -wget==3.2 -PyYAML==5.1.2 -google-cloud-storage==1.23.0 -Jinja2==2.11.1 -google-auth==1.11.0 diff --git a/requirements.txt b/requirements.txt new file mode 120000 index 00000000..453e1eff --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +sync/requirements.txt \ No newline at end of file diff --git a/runtime.txt b/runtime.txt deleted file mode 100644 index 548d7136..00000000 --- a/runtime.txt +++ /dev/null @@ -1 +0,0 @@ -3.7 \ No newline at end of file diff --git a/runtime.txt b/runtime.txt new file mode 120000 index 00000000..5f772b9a --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +sync/runtime.txt \ No newline at end of file diff --git a/sync/Dockerfile b/sync/Dockerfile new file mode 100644 index 00000000..85d97702 --- /dev/null +++ b/sync/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.7 + +WORKDIR /app +# Only copy specific values instead of the entire directory. +# We're primarily trying to avoid pulling in config/, since it's confusing that +# it will not be used. +COPY sync.py sync.py +COPY requirements.txt requirements.txt + +RUN pip install -r requirements.txt + +ENTRYPOINT [ "python3", "sync.py" ] diff --git a/sync/README.md b/sync/README.md index 909df748..ab7e0ace 100644 --- a/sync/README.md +++ b/sync/README.md @@ -1,3 +1,5 @@ +# sync + This directory includes a helper script for synchronizing contents from specified Tekton repositories to this repository. @@ -5,7 +7,19 @@ To run this script locally, set up a Python 3 environment with appropriate Google Cloud Platform credentials, and execute the following command: ```bash -cd .. -pip install -r requirements.txt -python sync/sync.py +pip3 install -r requirements.txt +python3 sync.py +``` + +## Usage + +```bash + USAGE: sync.py [flags] +flags: + +sync.py: + -c,--config: Config directory + (default: 'config') + +Try --helpfull to get a list of all flags. ``` diff --git a/sync/requirements.txt b/sync/requirements.txt new file mode 100644 index 00000000..3eff7fdb --- /dev/null +++ b/sync/requirements.txt @@ -0,0 +1,6 @@ +wget==3.2 +PyYAML==5.1.2 +google-cloud-storage==1.23.0 +Jinja2==2.11.1 +google-auth==1.14.0 +absl-py==0.9.0 \ No newline at end of file diff --git a/sync/runtime.txt b/sync/runtime.txt new file mode 100644 index 00000000..548d7136 --- /dev/null +++ b/sync/runtime.txt @@ -0,0 +1 @@ +3.7 \ No newline at end of file diff --git a/sync/sync.py b/sync/sync.py index c1ab8e25..073e5ae3 100644 --- a/sync/sync.py +++ b/sync/sync.py @@ -8,14 +8,23 @@ import re import shutil -from jinja2 import Environment, FileSystemLoader +from absl import app +from absl import flags +from jinja2 import Environment +from jinja2 import FileSystemLoader import wget -from yaml import load, Loader +from yaml import load +from yaml import Loader +FLAGS = flags.FLAGS + +# Flag names are globally defined! So in general, we need to be +# careful to pick names that are unlikely to be used by other libraries. +# If there is a conflict, we'll get an error at import time. +flags.DEFINE_string('config', os.path.dirname(os.path.abspath(__file__)) + '/config', 'Config directory', short_name='c') CONTENT_DIR = './content/en/docs' JS_ASSET_DIR = './assets/js' -SYNC_DIR = './sync/config' TEMPLATE_DIR = './templates' VAULT_DIR = './content/en/vault' BUCKET_NAME = 'tekton-website-assets' @@ -118,8 +127,8 @@ def scan(dir_path): return sync_config_paths -if __name__ == '__main__': - sync_config_paths = scan(f'./{SYNC_DIR}') +def main(argv): + sync_config_paths = scan(f'{FLAGS.config}') sync_configs = [] for sync_config_path in sync_config_paths: with open(sync_config_path) as f: @@ -130,3 +139,6 @@ def scan(dir_path): component_versions = get_component_versions(sync_configs) prepare_version_switcher_script(component_versions) prepare_vault_landing_page(component_versions) + +if __name__ == '__main__': + app.run(main) \ No newline at end of file