Sign inSign up

pylab/py36-node10

By pylab

Updated over 6 years ago

Plz see the Readme to get the new style. Merge python 3.6 & node 10.11.

Image
0

1.2K

pylab/py36-node10 repository overview

Dockerfile

~~ > Just copy one to another. ~~

Update new style

ARG NODE_VER=10.19-alpine3.10
ARG PYTHON_VER=3.6-alpine3.10

FROM node:${NODE_VER} as builder
FROM python:${PYTHON_VER}

COPY --from=builder /usr/local/ /usr/local
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64 /usr/bin/dumb-init
RUN chmod +x /usr/bin/dumb-init

ENTRYPOINT ["dumb-init", "--"]

Tag

  • alpine3.10 (latest)
  • slim-jessie
  • slim-stretch
  • slim-buster

Merge script


#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import OrderedDict


class KEYWORDS(object):
    __dict__ = OrderedDict()

    FROM = []
    ENV = []
    RUN = []
    LABEL = []
    EXPOSE = []
    ADD = []
    COPY = []
    VOLUME = []
    USER = []
    WORKDIR = []
    ARG = []
    ONBUILD = []
    STOPSIGNAL = []
    HEALTHCHECK = []
    SHELL = []
    CMD = []
    ENTRYPOINT = []


class Dockerfile(KEYWORDS):
    SEPARATOR = [";", "&&"]

    def __init__(self, name=None):
        super(Dockerfile, self).__init__()
        self.NAME = name

        if name:
            self.dockerfile = get(name)


def get(url):
    import urllib.request

    headers = {
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
    }

    req = urllib.request.Request(url, headers=headers)
    with urllib.request.urlopen(req) as response:
        html = response.readlines()
        return html


def handle_dockerfile(body: list, inst=None):
    if not inst:
        inst = Dockerfile()

    keywords = KEYWORDS.__dict__.keys()
    flag_slash = False
    cur_keyword = None
    cur_line = []

    for line in body:
        line = line.strip()

        if not isinstance(line, str):
            line = line.decode()

        if line.startswith("#") or not line:
            continue

        else:
            cur_line.append(line)

        if not cur_keyword and not flag_slash:
            cur_keyword = line.split(" ", 1)[0]

        if line.endswith("\\") or (line.startswith("&") and line.endswith("\\")):
            flag_slash = True
        else:
            flag_slash = False

        if not flag_slash:
            if cur_keyword in keywords:
                attr = getattr(inst, cur_keyword)
                attr.append("".join(cur_line))

            else:
                print("error: {}".format(cur_line))

            cur_keyword = None
            cur_line = []

    return inst


def generate_dockerfile():
    keywords = [k for k in KEYWORDS.__dict__.keys() if not k.startswith("_")]
    for key in keywords:
        lines = getattr(KEYWORDS, key, [])

        if len(lines) > 0:
            if key in ["FROM", "ENTRYPOINT", "CMD"]:
                print(lines[-1])
                continue

            if key in ["RUN"]:
                first = lines[0]
                second = list(map(lambda x: x.replace("RUN", "\\\n&&"), lines[1:]))
                line = "".join([first] + second)
                # for line in second:
                line = line.replace("\\(", "`@(`")  # 转义 换行
                line = line.replace("\\)", "`@)`")  # 转义 换行
                line = line.replace(" \\", " \\\n")  # 换行

                line = line.replace("`@(`", "\\(")
                line = line.replace("`@)`", "\\)")
                # first+=line
                print(line)
                continue

            for idx, l in enumerate(lines, start=1):
                print(l)


def merge():
    try:
        assert len(set(KEYWORDS.FROM)) == 1
    except AssertionError:
        raise Exception("Not in same image: {}".format(KEYWORDS.FROM))

    generate_dockerfile()


if __name__ == "__main__":
    df1 = Dockerfile(
        ""
    )
    df2 = Dockerfile(
        ""
    )

    handle_dockerfile(df1.dockerfile)
    handle_dockerfile(df2.dockerfile)

    merge()

Tag summary

Content type

Image

Digest

Size

51.9 MB

Last updated

over 6 years ago

docker pull pylab/py36-node10