Skip to content

Commit

Permalink
Bug 1622800 - part 5: Schedule a single screenshot job to Bitrise
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLorenzo committed Apr 7, 2020
1 parent 324fc94 commit f451a8f
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 0 deletions.
14 changes: 14 additions & 0 deletions taskcluster/ci/docker-image/kind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
---

loader: taskgraph.loader.transform:loader

transforms:
- taskgraph.transforms.docker_image:transforms
- taskgraph.transforms.cached_tasks:transforms
- taskgraph.transforms.task:transforms

jobs:
screenshots: {}
50 changes: 50 additions & 0 deletions taskcluster/ci/generate-screenshots/kind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
---
loader: taskgraph.loader.transform:loader

transforms:
- ffios_taskgraph.transforms.screenshots:transforms
- ffios_taskgraph.transforms.secrets:transforms
- taskgraph.transforms.job:transforms
- taskgraph.transforms.task:transforms


job-defaults:
description: Generate localized screenshots by delegating the work to bitrise.io
run:
using: run-commands
use-caches: false
secrets:
by-level:
'3':
- name: project/mobile/firefox-ios/bitrise
key: api_key
path: .bitrise_token
default: []
dummy-secrets:
by-level:
'3': []
default:
- content: "faketoken"
path: .bitrise_token
run-on-tasks-for: []
worker:
artifacts:
- type: file
name: public/logs/bitrise.log
path: /builds/worker/checkouts/src/bitrise.log
docker-image: {in-tree: screenshots}
max-run-time: 3600
worker-type: b-linux

jobs:
fr:
locale: fr
worker:
# TODO: Move artifacts in transforms once we start supporting all locales
artifacts:
- type: file
name: public/screenshots/fr.zip
path: /builds/worker/checkouts/src/fr.zip
54 changes: 54 additions & 0 deletions taskcluster/docker/screenshots/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

FROM ubuntu:18.04

MAINTAINER Johan Lorenzo "[email protected]"

# Add worker user
RUN mkdir /builds && \
useradd -d /builds/worker -s /bin/bash -m worker && \
chown worker:worker /builds/worker && \
mkdir /builds/worker/artifacts && \
chown worker:worker /builds/worker/artifacts

WORKDIR /builds/worker/


ENV CURL='curl --location --retry 5' \
LANG='en_US.UTF-8' \
TERM='dumb'


RUN apt-get update -qq \
# We need to install tzdata before all of the other packages. Otherwise it will show an interactive dialog that
# we cannot navigate while building the Docker image.
&& apt-get install -y tzdata \
&& apt-get install -y curl \
git \
locales \
mercurial \
python3 \
python3-pip \
&& apt-get clean

RUN pip3 install --upgrade pip
COPY requirements.txt ./
RUN pip3 install -r requirements.txt

RUN locale-gen "$LANG"

# %include-run-task

ENV SHELL=/bin/bash \
HOME=/builds/worker \
PATH="/builds/worker/.local/bin:$PATH"


VOLUME /builds/worker/checkouts
VOLUME /builds/worker/.cache


# run-task expects to run as root
USER root
2 changes: 2 additions & 0 deletions taskcluster/docker/screenshots/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
aiohttp-retry
taskcluster
2 changes: 2 additions & 0 deletions taskcluster/ffios_taskgraph/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def configure_run_commands_schema(config, job, taskdesc):

def _generate_secret_command(secret):
secret_command = [
"python3", # XXX Other mobile projects run this script under python2
"taskcluster/scripts/get-secret.py",
"-s", secret["name"],
"-k", secret["key"],
Expand All @@ -70,6 +71,7 @@ def _generate_secret_command(secret):

def _generate_dummy_secret_command(secret):
secret_command = [
"python3", # XXX Other mobile projects run this script under python2
"taskcluster/scripts/write-dummy-secret.py",
"-f", secret["path"],
"-c", secret["content"],
Expand Down
Empty file.
30 changes: 30 additions & 0 deletions taskcluster/ffios_taskgraph/transforms/screenshots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
Resolve secrets and dummy secrets
"""

from __future__ import absolute_import, print_function, unicode_literals

from taskgraph.transforms.base import TransformSequence


transforms = TransformSequence()


@transforms.add
def add_command(config, tasks):
for task in tasks:
commands = task["run"].setdefault("commands", [])
locale = task.pop("locale")
commands.append([
"python3",
"taskcluster/scripts/generate-screenshots.py",
"--token-file", ".bitrise_token",
"--branch", config.params["head_ref"],
"--commit", config.params["head_rev"],
"--locale", locale
])

yield task
27 changes: 27 additions & 0 deletions taskcluster/ffios_taskgraph/transforms/secrets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
Resolve secrets and dummy secrets
"""

from __future__ import absolute_import, print_function, unicode_literals

from taskgraph.transforms.base import TransformSequence
from taskgraph.util.schema import resolve_keyed_by


transforms = TransformSequence()


@transforms.add
def resolve_keys(config, tasks):
for task in tasks:
for key in ("run.secrets", "run.dummy-secrets"):
resolve_keyed_by(
task,
key,
item_name=task["name"],
level=config.params["level"]
)
yield task
Loading

0 comments on commit f451a8f

Please sign in to comment.