Skip to content

Commit

Permalink
Linter, Test fixes, and Container Updates (#620)
Browse files Browse the repository at this point in the history
* Fix lint errors

* Fix test errors by removing six

* Fix lint errors

* Update containers with new helm/kubectl versions (#621)

* Update helm, kubectl and container dependencies

* Fix docker install

* Revert changes to test docker container
  • Loading branch information
gibbleyg authored Dec 5, 2023
1 parent ef3dfa3 commit 4a9ff1e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 30 deletions.
6 changes: 3 additions & 3 deletions marketplace/deployer_envsubst_base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM marketplace.gcr.io/google/ubuntu2004
FROM marketplace.gcr.io/google/ubuntu2204

RUN apt-get update && apt-get install -y --no-install-recommends \
bash \
Expand All @@ -17,15 +17,15 @@ RUN pip3 install \
pyyaml \
six

RUN for full_version in 1.26.5 1.26.5 1.27.2; \
RUN for full_version in 1.27.3 1.28.3; \
do \
version=${full_version%.*} \
&& mkdir -p /opt/kubectl/$version \
&& wget -q -O /opt/kubectl/$version/kubectl \
https://storage.googleapis.com/kubernetes-release/release/v$full_version/bin/linux/amd64/kubectl \
&& chmod 755 /opt/kubectl/$version/kubectl; \
done;
RUN ln -s /opt/kubectl/1.26 /opt/kubectl/default
RUN ln -s /opt/kubectl/1.27 /opt/kubectl/default

COPY marketplace/deployer_envsubst_base/* /bin/
COPY marketplace/deployer_util/* /bin/
Expand Down
11 changes: 5 additions & 6 deletions marketplace/deployer_helm_base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM marketplace.gcr.io/google/ubuntu2004
FROM marketplace.gcr.io/google/ubuntu2204

RUN apt-get update && apt-get install -y --no-install-recommends \
bash \
Expand All @@ -14,22 +14,21 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
RUN pip3 install \
wheel \
pyOpenSSL \
pyyaml \
six
pyyaml

RUN for full_version in 1.26.5 1.26.5 1.27.2; \
RUN for full_version in 1.27.3 1.28.3; \
do \
version=${full_version%.*} \
&& mkdir -p /opt/kubectl/$version \
&& wget -q -O /opt/kubectl/$version/kubectl \
https://storage.googleapis.com/kubernetes-release/release/v$full_version/bin/linux/amd64/kubectl \
&& chmod 755 /opt/kubectl/$version/kubectl; \
done;
RUN ln -s /opt/kubectl/1.26 /opt/kubectl/default
RUN ln -s /opt/kubectl/1.27 /opt/kubectl/default

RUN mkdir -p /bin/helm-downloaded \
&& wget -q -O /bin/helm-downloaded/helm.tar.gz \
https://get.helm.sh/helm-v3.12.2-linux-amd64.tar.gz \
https://get.helm.sh/helm-v3.13.2-linux-amd64.tar.gz \
&& tar -zxvf /bin/helm-downloaded/helm.tar.gz -C /bin/helm-downloaded \
&& mv /bin/helm-downloaded/linux-amd64/helm /bin/ \
&& rm -rf /bin/helm-downloaded
Expand Down
10 changes: 5 additions & 5 deletions marketplace/deployer_util/bash_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import shlex
import subprocess

import six


class CommandException(Exception):

Expand All @@ -39,7 +37,11 @@ def __init__(self, cmd, print_call=False, print_result=False):

parsedCmd = shlex.split(cmd)
self._process = subprocess.Popen(
parsedCmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
parsedCmd,
stdin=None,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding='utf-8')
self._exitcode = None
self._output = None
self._print_call = print_call
Expand All @@ -48,8 +50,6 @@ def __init__(self, cmd, print_call=False, print_result=False):

def _run(self):
self._output, error_message = self._process.communicate()
self._output = six.ensure_str(self._output, 'utf-8')
error_message = six.ensure_str(error_message, 'utf-8')
self._exitcode = self._process.returncode
if self._print_result:
result = (f"result: {self._exitcode}\n"
Expand Down
4 changes: 1 addition & 3 deletions marketplace/deployer_util/make_dns1123_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import re
from argparse import ArgumentParser

import six

_PROG_HELP = """
Turns a name into a proper DNS-1123 subdomain, with limitations.
"""
Expand Down Expand Up @@ -54,7 +52,7 @@ def limit_name(name, length=127):
result = result[:length - 5]
# Hash and get the first 4 characters of the hash.
m = hashlib.sha256()
m.update(six.ensure_binary(name, 'utf-8'))
m.update(name.encode('utf-8'))
h4sh = m.hexdigest()[:4]
result = '{}-{}'.format(result, h4sh)
return result
Expand Down
7 changes: 4 additions & 3 deletions marketplace/deployer_util/process_helm_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

_HELM_HOOK_KEY = 'helm.sh/hook'
_HOOK_SUCCESS = ['test-success', 'test']
_HOOK_FAILURE = ['test-failure', 'test']
_HOOK_FAILURE = ['test-failure']


def main():
parser = ArgumentParser()
Expand All @@ -44,13 +45,13 @@ def main():
helm_hook = deep_get(resource, "metadata", "annotations", _HELM_HOOK_KEY)
if helm_hook is None:
filtered_resources.append(resource)
elif _HOOK_SUCCESS.index(helm_hook):
elif helm_hook in _HOOK_SUCCESS:
if args.deploy_tests:
annotations = deep_get(resource, "metadata", "annotations")
del annotations[_HELM_HOOK_KEY]
annotations[GOOGLE_CLOUD_TEST] = "test"
filtered_resources.append(resource)
elif _HOOK_FAILURE.index(helm_hook):
elif helm_hook in _HOOK_FAILURE:
if args.deploy_tests:
raise Exception("Helm hook {} is not supported".format(helm_hook))
else:
Expand Down
17 changes: 7 additions & 10 deletions marketplace/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM marketplace.gcr.io/google/ubuntu2004
FROM marketplace.gcr.io/google/ubuntu2204

RUN apt-get update && apt-get install -y --no-install-recommends \
apt-transport-https \
Expand All @@ -13,7 +13,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
gnupg \
python3 \
python3-pip \
python-is-python3 \
&& rm -rf /var/lib/apt/lists/*

RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \
Expand All @@ -24,27 +23,25 @@ RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.c
RUN pip3 install \
wheel \
pyOpenSSL \
pyyaml \
six
pyyaml

RUN for full_version in 1.26.5 1.26.5 1.27.2; \
RUN for full_version in 1.27.3 1.28.3; \
do \
version=${full_version%.*} \
&& mkdir -p /opt/kubectl/$version \
&& wget -q -O /opt/kubectl/$version/kubectl \
https://storage.googleapis.com/kubernetes-release/release/v$full_version/bin/linux/amd64/kubectl \
&& chmod 755 /opt/kubectl/$version/kubectl; \
done;
RUN ln -s /opt/kubectl/1.26 /opt/kubectl/default
RUN ln -s /opt/kubectl/1.27 /opt/kubectl/default

RUN echo "deb [signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu focal edge" | tee /etc/apt/sources.list.d/docker.list \
RUN echo "deb [signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable" | tee /etc/apt/sources.list.d/docker.list \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key --keyring /usr/share/keyrings/docker.gpg add - \
&& apt-get -y update \
&& apt-get -y install docker-ce=5:19.03.13~3-0~ubuntu-focal

&& apt-get -y install docker-ce
RUN mkdir -p /bin/helm-downloaded \
&& wget -q -O /bin/helm-downloaded/helm.tar.gz \
https://get.helm.sh/helm-v3.12.2-linux-amd64.tar.gz \
https://get.helm.sh/helm-v3.13.2-linux-amd64.tar.gz \
&& tar -zxvf /bin/helm-downloaded/helm.tar.gz -C /bin/helm-downloaded \
&& mv /bin/helm-downloaded/linux-amd64/helm /bin/ \
&& rm -rf /bin/helm-downloaded
Expand Down

0 comments on commit 4a9ff1e

Please sign in to comment.