Skip to content

Commit

Permalink
support multiarch builds using buildx (amd64/arm64)
Browse files Browse the repository at this point in the history
  • Loading branch information
justincarter committed Aug 11, 2021
1 parent 30ec932 commit cd29faf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.py text eol=lf
*.sh text eol=lf
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile.nginx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 28 additions & 8 deletions build-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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']
Expand All @@ -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,
".",
]

Expand All @@ -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()
6 changes: 6 additions & 0 deletions matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd29faf

Please sign in to comment.