diff --git a/.gitattributes b/.gitattributes index dfdb8b7..61d299b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ +*.py text eol=lf *.sh text eol=lf diff --git a/.travis.yml b/.travis.yml index e406730..2e52793 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,11 @@ before_script: - docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - pip3 install -r requirements.txt - python3 ./generate-matrix.py >/dev/null && git diff --exit-code +- mkdir -vp ~/.docker/cli-plugins/ +- curl --silent -L "https://github.com/docker/buildx/releases/download/v0.5.1/buildx-v0.5.1.linux-amd64" > ~/.docker/cli-plugins/docker-buildx +- chmod a+x ~/.docker/cli-plugins/docker-buildx +- docker buildx version +- docker buildx create --use dist: bionic env: jobs: diff --git a/Dockerfile b/Dockerfile index 0430ec0..57fa1e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,9 @@ ARG TOMCAT_BASE_IMAGE FROM docker.io/library/tomcat:${TOMCAT_VERSION}-${TOMCAT_JAVA_VERSION}${TOMCAT_BASE_IMAGE} +ARG TARGETPLATFORM +ARG BUILDPLATFORM + ARG LUCEE_VERSION ARG LUCEE_MINOR ARG LUCEE_SERVER diff --git a/Dockerfile.nginx b/Dockerfile.nginx index 23a9084..d4a4189 100644 --- a/Dockerfile.nginx +++ b/Dockerfile.nginx @@ -2,6 +2,9 @@ ARG LUCEE_IMAGE FROM ${LUCEE_IMAGE} +ARG TARGETPLATFORM +ARG BUILDPLATFORM + # Install nginx and supervisord COPY nginx/nginx_signing.key /tmp/nginx_signing.key RUN apt-key add /tmp/nginx_signing.key diff --git a/build-images.py b/build-images.py index 8a521c0..65418bd 100755 --- a/build-images.py +++ b/build-images.py @@ -116,12 +116,25 @@ def main(): help='do not push the tags') parser.add_argument('--list-tags', action='store_true', default=False, help='only list the tags that would be generated') + parser.add_argument('--buildx-platform', dest='platform', action='store', default='linux/amd64,linux/arm64', + help='the target platform(s) to build, e.g. linux/amd64,linux/arm64') + parser.add_argument('--buildx-load', dest='load', action='store_true', default=False, + help='load the image into Docker from the builder') args = parser.parse_args() if args.list_tags: args.push = False args.build = False + if os.getenv('LUCEE_TARGETPLATFORM', None): + args.platform = os.getenv('LUCEE_TARGETPLATFORM', 'linux/amd64,linux/arm64') + + if args.load: + args.push = False + if ',' in args.platform: + sys.exit("A single target platform must be specified when using load") + + if args.version == None: print("version argument missing or $LUCEE_VERSION not set") sys.exit(1) @@ -131,7 +144,7 @@ def main(): is_master_build = os.getenv('TRAVIS_PULL_REQUEST', None) == 'false' if os.getenv('CI', None): - print('will we deploy:', 'yes' if is_master_build else 'no') + print('will we deploy:', 'yes' if is_master_build and args.push else 'no') namespace = matrix['config']['docker_hub_namespace'] image_name = matrix['config']['docker_hub_image'] @@ -154,11 +167,24 @@ def main(): plain_tags = [f"{namespace}/{image_name}:{tag}" for tag in tags] tag_args = flatten([["-t", tag] for tag in plain_tags]) + buildx_args = [] + if args.load: + buildx_args = [f"--load"] + + if is_master_build and args.push: + buildx_args = [f"--push"] + print('pushing', plain_tags) + else: + print('not a master build; skipping deployment of', plain_tags) + command = [ - "docker", "build", *docker_args, + "docker", "buildx", "build", *docker_args, *build_args, + "--platform", args.platform, + *buildx_args, "-f", dockerfile, *tag_args, + *buildx_args, ".", ] @@ -167,12 +193,6 @@ def main(): if args.build: run(command) - for tag in plain_tags: - if is_master_build and args.push: - print('pushing', tag) - run(["docker", "push", tag]) - else: - print('not on master; skipping deployment of', tag) if __name__ == '__main__': main() diff --git a/matrix.yaml b/matrix.yaml index eb47bd2..94af029 100644 --- a/matrix.yaml +++ b/matrix.yaml @@ -12,6 +12,12 @@ travis: - pip3 install -r requirements.txt # exit the build if the travis config is different from the matrix config - python3 ./generate-matrix.py >/dev/null && git diff --exit-code + # install buildx + - mkdir -vp ~/.docker/cli-plugins/ + - curl --silent -L "https://github.com/docker/buildx/releases/download/v0.5.1/buildx-v0.5.1.linux-amd64" > ~/.docker/cli-plugins/docker-buildx + - chmod a+x ~/.docker/cli-plugins/docker-buildx + - docker buildx version + - docker buildx create --use script: - echo $LUCEE_VERSION - python3 -u build-images.py