Skip to content

Commit

Permalink
Dockerize sync tool.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wlynch authored and tekton-robot committed Jun 15, 2020
1 parent 0039c98 commit 85a5dcb
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 14 deletions.
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
1 change: 0 additions & 1 deletion runtime.txt

This file was deleted.

1 change: 1 addition & 0 deletions runtime.txt
12 changes: 12 additions & 0 deletions sync/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
20 changes: 17 additions & 3 deletions sync/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
# sync

This directory includes a helper script for synchronizing contents
from specified Tekton repositories to this repository.

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.
```
6 changes: 6 additions & 0 deletions sync/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions sync/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.7
22 changes: 17 additions & 5 deletions sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand All @@ -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)

0 comments on commit 85a5dcb

Please sign in to comment.