Skip to content

Commit

Permalink
images/bootstrap: added arm64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Jul 28, 2021
1 parent 79c8eab commit bf714f0
Show file tree
Hide file tree
Showing 16 changed files with 2,715 additions and 4 deletions.
19 changes: 15 additions & 4 deletions images/bootstrap/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
ENV PATH=/google-cloud-sdk/bin:/workspace:${PATH} \
CLOUDSDK_CORE_DISABLE_PROMPTS=1

RUN wget -q https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz && \
tar xzf google-cloud-sdk.tar.gz -C / && \
rm google-cloud-sdk.tar.gz && \
ENV GCLOUD_VERSION=349.0.0

RUN set -eux; \
\
case $(uname -m) in \
x86_64) export GCLOUD_TAR_FILE="google-cloud-sdk-${GCLOUD_VERSION}-linux-x86_64.tar.gz" ;; \
aarch64) export GCLOUD_TAR_FILE="google-cloud-sdk-${GCLOUD_VERSION}-linux-arm.tar.gz" ;; \
*) echo "unsupported architecture"; exit 1 ;; \
esac; \
\
wget "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${GCLOUD_TAR_FILE}"; && \
tar xzf ${GCLOUD_TAR_FILE} -C / && \
rm ${GCLOUD_TAR_FILE} && \
/google-cloud-sdk/install.sh \
--disable-installation-options \
--bash-completion=false \
Expand All @@ -93,10 +103,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
rm -rf /var/lib/apt/lists/*

# Add the Docker apt-repository
ARG TARGETARCH
RUN curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg \
| apt-key add - && \
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
"deb [arch=${TARGETARCH:-amd64}] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) stable"

# Install Docker
Expand Down
37 changes: 37 additions & 0 deletions images/bootstrap/scenarios/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package(default_visibility = ["//visibility:public"])

filegroup(
name = "scenarios",
srcs = glob(["*.py"]),
)

filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)

filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)

py_test(
name = "kubernetes_e2e_test",
srcs = [
"kubernetes_e2e.py",
"kubernetes_e2e_test.py",
],
python_version = "PY2",
)

py_test(
name = "kubernetes_bazel_test",
srcs = [
"kubernetes_bazel.py",
"kubernetes_bazel_test.py",
],
python_version = "PY2",
)
18 changes: 18 additions & 0 deletions images/bootstrap/scenarios/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See the OWNERS docs at https://go.k8s.io/owners

reviewers:
- amwat
- BenTheElder
- MushuEE
- spiffxp
approvers:
- amwat
- BenTheElder
- spiffxp
emeritus_approvers:
- cjwagner
- fejta
- krzyzacy

labels:
- area/scenarios
49 changes: 49 additions & 0 deletions images/bootstrap/scenarios/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# DEPRECATION NOTICE

*October 9, 2018* `scenarios/*.py` will be moved to become part of kubetest v2, so we are
not taking PRs except for urgent bug fixes.

Also please bump [bootstrap image](/images/bootstrap) and
[kubekins image](/images/kubekins-e2e) to take in any future changes.

# Test scenarios

Place scripts to run test scenarios inside this location.

Test jobs are composed of two things:
1) A scenario to test
2) Configuration options for the scenario.

Three example scenarios are:

* Unit tests
* Node e2e tests
* e2e tests

Example configurations are:

* Parallel tests on gce
* Build all platforms

The assumption is that each scenario will be called a variety of times with
different configuration options. For example at the time of this writing there
are over 300 e2e jobs, each run with a slightly different set of options.

## Contract

The scenario assumes the calling process (bootstrap.py) has setup all
prerequisites, such as checking out the right repository, setting pwd,
activating service accounts, etc.

The scenario also assumes that the calling process will handle all post-job
works, such as recording log output, copying logs to gcs, etc.

The scenario should exit 0 if and only on success.

The calling process can configure the scenario by calling the scenario
with different arguments. For example: `kubernetes\_build.py --fast`
configures the scenario to do a fast build (one platform) and/or
`kubernetes\_build.py --federation=random-project` configures the scenario
to do a federation build using the random-project.

Call the scenario with `-h` to see configuration options.
89 changes: 89 additions & 0 deletions images/bootstrap/scenarios/canarypush.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python

# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Need to figure out why this only fails on travis
# pylint: disable=bad-continuation

"""Executes a command."""

import argparse
import os
import subprocess
import sys

def check_with_log(*cmd):
"""Log and run the command, raising on errors."""
print >>sys.stderr, 'Run:', cmd
print >>sys.stderr, subprocess.check_call(cmd)

def check_no_log(*cmd):
"""Run the command, raising on errors, no logs"""
try:
subprocess.check_call(cmd)
except:
raise subprocess.CalledProcessError(cmd='subprocess.check_call', returncode=1)

def check_output(*cmd):
"""Log and run the command, return output, raising on errors."""
print >>sys.stderr, 'Run:', cmd
return subprocess.check_output(cmd)


def main(target, buildfile):
"""Build & push to canary."""
check_with_log(
'docker', 'build', '-t', target, '--no-cache=true',
'--pull=true', '--file=%s' % buildfile, '.'
)
check_with_log('docker', 'inspect', target)

user = None
if os.path.exists(os.environ.get('DOCKER_USER')):
with open(os.environ.get('DOCKER_USER'), 'r') as content_file:
user = content_file.read()

pwd = None
if os.path.exists(os.environ.get('DOCKER_PASSWORD')):
with open(os.environ.get('DOCKER_PASSWORD'), 'r') as content_file:
pwd = content_file.read()

if not user or not pwd:
print >>sys.stderr, 'Logging info not exist'
sys.exit(1)
print >>sys.stderr, 'Logging in as %r' % user
check_no_log('docker', 'login', '--username=%s' % user, '--password=%s' % pwd)

os.environ.pop('DOCKER_USER', None)
os.environ.pop('DOCKER_PASSWORD', None)

check_with_log('docker', 'push', target)
check_with_log('docker', 'logout')


if __name__ == '__main__':
PARSER = argparse.ArgumentParser()
PARSER.add_argument(
'--owner', help='Owner of the job')
PARSER.add_argument(
'--target', help='Build target')
PARSER.add_argument(
'--file', help='Build files')
ARGS = PARSER.parse_args()
if not ARGS.target or not ARGS.file:
raise ValueError('--target and --file must be set!')
if ARGS.owner:
os.environ['OWNER'] = ARGS.owner
main(ARGS.target, ARGS.file)
56 changes: 56 additions & 0 deletions images/bootstrap/scenarios/dindind_execute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python

# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Need to figure out why this only fails on travis
# pylint: disable=bad-continuation

"""Prepares for nested docker, and executes a command."""
# TODO(Q-Lee): check the necessity of this once MountPropagation is available in
# prow: https://github.com/kubernetes/kubernetes/pull/59252

import argparse
import os
import subprocess
import sys

def check(*cmd):
"""Log and run the command, raising on errors."""
print >>sys.stderr, 'Run:', cmd
subprocess.check_call(cmd)


def main(envs, cmd):
"""Make important mounts r-shared, then run script and verify it exits 0."""
check("mount", "--make-rshared", "/lib/modules")
check("mount", "--make-rshared", "/sys")
check("mount", "--make-rshared", "/")

for env in envs:
key, val = env.split('=', 1)
print >>sys.stderr, '%s=%s' % (key, val)
os.environ[key] = val
if not cmd:
raise ValueError(cmd)
check(*cmd)


if __name__ == '__main__':
PARSER = argparse.ArgumentParser()
PARSER.add_argument('--env', default=[], action='append')
PARSER.add_argument('cmd', nargs=1)
PARSER.add_argument('args', nargs='*')
ARGS = PARSER.parse_args()
main(ARGS.env, ARGS.cmd + ARGS.args)
50 changes: 50 additions & 0 deletions images/bootstrap/scenarios/execute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python

# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Need to figure out why this only fails on travis
# pylint: disable=bad-continuation

"""Executes a command."""

import argparse
import os
import subprocess
import sys

def check(*cmd):
"""Log and run the command, raising on errors."""
print >>sys.stderr, 'Run:', cmd
subprocess.check_call(cmd)


def main(envs, cmd):
"""Run script and verify it exits 0."""
for env in envs:
key, val = env.split('=', 1)
print >>sys.stderr, '%s=%s' % (key, val)
os.environ[key] = val
if not cmd:
raise ValueError(cmd)
check(*cmd)


if __name__ == '__main__':
PARSER = argparse.ArgumentParser()
PARSER.add_argument('--env', default=[], action='append')
PARSER.add_argument('cmd', nargs=1)
PARSER.add_argument('args', nargs='*')
ARGS = PARSER.parse_args()
main(ARGS.env, ARGS.cmd + ARGS.args)
Loading

0 comments on commit bf714f0

Please sign in to comment.