1- # Recipies for this Makefile
1+ # Recipes for this Makefile
22
33# # Build all docker images
4- # # $ make DOCKER_TAG=nightly CRYSTAL_VERSION=0.xy.z
5- # # Build ubuntu64 docker images
6- # # $ make ubuntu64 DOCKER_TAG=nightly CRYSTAL_VERSION=0.xy.z
7- # # Build alpine docker images
8- # # $ make alpine DOCKER_TAG=nightly CRYSTAL_VERSION=0.xy.z
4+ # # $ make VERSION=1.18.2
5+ # # Build specific docker images
6+ # # $ make build-ubuntu VERSION=1.18.2
7+ # # $ make build-alpine-build VERSION=1.18.2
8+ # #
9+ # # Push all docker images to registry
10+ # # $ make push VERSION=1.18.2
11+ # # Push a specific docker image to registry
12+ # # $ make push-ubuntu VERSION=1.18.2
13+ # # $ make push-alpine-build VERSION=1.18.2
914# #
1015# # Run smoke tests
1116# # $ make smoke-all
1217# # $ make smoke-ubuntu-build
1318# # $ make smoke-alpine-runtime
1419
15- CRYSTAL_VERSION ?= # # How the binaries should be branded
16- TARBALLS ?= tarballs# # Path to folder which contains the Crystal tarballs to install in docker images.
17-
18- DOCKER_TAG ?= $(CRYSTAL_VERSION ) # # How to tag the docker image (examples: `0.27.2`, `nightly20190307`). `-build` will be appended for build images.
19- DOCKER_REPOSITORY ?= crystallang/crystal# # Docker hub repository to commit image
20+ VERSION ?= # # Version name of the source tarballs
21+ TARBALLS ?= ./tarballs# # Path to folder which contains the Crystal tarballs to install in docker images.
2022
21- OUTPUT_DIR := build
22- BUILD_CONTEXT := build-context
23- DOCKER_TAG_UBUNTU := $(DOCKER_REPOSITORY ) :$(DOCKER_TAG )
24- DOCKER_TAG_ALPINE := $(DOCKER_REPOSITORY ) :$(DOCKER_TAG ) -alpine
23+ BUILD_CONTEXT := ./build-context
24+ TAG := crystallang/crystal:$(VERSION ) # # Base tag of the docker image. Classifiers like `-ubuntu` and `-build` will be appended.
2525
26- .PHONY : all64
27- all64 : ubuntu64 alpine # # Build all x86_64 images
26+ PLATFORMS := linux/amd64
27+ PLATFORM_TARBALLS := $( patsubst linux/ % , $( BUILD_CONTEXT ) /crystal- % .tar.gz, $( PLATFORMS ) )
2828
29- .PHONY : all_ubuntu
30- all_ubuntu : ubuntu64 # # Build all ubuntu images
29+ .PHONY : all
30+ all : # # Build all images
31+ all : build-ubuntu
32+ all : build-ubuntu-build
33+ all : build-alpine
34+ all : build-alpine-build
3135
32- .PHONY : ubuntu64
33- ubuntu64 : # # Build ubuntu x86_64 images
34- ubuntu64 : $(OUTPUT_DIR ) /docker-$(CRYSTAL_VERSION ) -ubuntu-x86_64.tar.gz
35- ubuntu64 : $(OUTPUT_DIR ) /docker-$(CRYSTAL_VERSION ) -ubuntu-x86_64-build.tar.gz
36+ .PHONY : push
37+ push : # # Push all images to the registry
38+ push : push-ubuntu
39+ push : push-ubuntu-build
40+ push : push-alpine
41+ push : push-alpine-build
3642
37- .PHONY : alpine
38- alpine : # # Build alpine images
39- alpine : $(OUTPUT_DIR ) /docker-$(CRYSTAL_VERSION ) -alpine.tar.gz
40- alpine : $(OUTPUT_DIR ) /docker-$(CRYSTAL_VERSION ) -alpine-build.tar.gz
43+ push-% :
44+ docker push $(TAG )$(subst -ubuntu,,-$* )
4145
42- $(BUILD_CONTEXT ) /crystal-amd64.tar.gz : $(TARBALLS ) /crystal-$(CRYSTAL_VERSION ) -1-linux-x86_64.tar.gz | $(BUILD_CONTEXT )
46+ $(BUILD_CONTEXT ) /crystal-amd64.tar.gz : $(TARBALLS ) /crystal-$(VERSION ) -1-linux-x86_64.tar.gz | $(BUILD_CONTEXT )
4347 cp $< $@
4448
45- $(OUTPUT_DIR ) $( BUILD_CONTEXT ) :
49+ $(BUILD_CONTEXT ) :
4650 mkdir -p $@
4751
48- # Ubuntu x86_64
49- $(OUTPUT_DIR ) /docker-$(CRYSTAL_VERSION ) -ubuntu-x86_64.tar.gz : ubuntu.Dockerfile $(BUILD_CONTEXT ) /crystal-amd64.tar.gz $(OUTPUT_DIR )
50- docker build --file ubuntu.Dockerfile -t $(DOCKER_TAG_UBUNTU ) --target runtime $(BUILD_CONTEXT )
51- docker save $(DOCKER_TAG_UBUNTU ) | gzip > $@
52+ .PHONY : build-alpine
53+ build-alpine : alpine.Dockerfile $(PLATFORM_TARBALLS )
54+ docker build --file alpine.Dockerfile -t $(TAG ) -alpine --target runtime $(BUILD_CONTEXT )
5255
53- $( OUTPUT_DIR ) /docker- $( CRYSTAL_VERSION ) -ubuntu-x86_64-build.tar.gz : ubuntu.Dockerfile $( BUILD_CONTEXT ) /crystal-amd64.tar.gz $( OUTPUT_DIR )
54- docker build --file ubuntu .Dockerfile -t $( DOCKER_TAG_UBUNTU ) -build --target build $( BUILD_CONTEXT )
55- docker save $( DOCKER_TAG_UBUNTU ) - build | gzip > $@
56+ .PHONY : build-alpine-build
57+ build-alpine-build : alpine .Dockerfile $( PLATFORM_TARBALLS )
58+ docker build --file alpine.Dockerfile -t $( TAG ) -alpine- build --target build $( BUILD_CONTEXT )
5659
57- # Alpine x86_64
58- $(OUTPUT_DIR ) /docker-$(CRYSTAL_VERSION ) -alpine.tar.gz : alpine.Dockerfile $(BUILD_CONTEXT ) /crystal-amd64.tar.gz $(OUTPUT_DIR )
59- docker build --file alpine.Dockerfile -t $(DOCKER_TAG_ALPINE ) --target runtime $(BUILD_CONTEXT )
60- docker save $(DOCKER_TAG_ALPINE ) | gzip > $@
60+ .PHONY : build-ubuntu
61+ build-ubuntu : ubuntu.Dockerfile $(PLATFORM_TARBALLS )
62+ docker build --file ubuntu.Dockerfile -t $(TAG ) --target runtime $(BUILD_CONTEXT )
6163
62- $( OUTPUT_DIR ) /docker- $( CRYSTAL_VERSION ) -alpine-build.tar.gz : alpine.Dockerfile $( BUILD_CONTEXT ) /crystal-amd64.tar.gz $( OUTPUT_DIR )
63- docker build --file alpine .Dockerfile -t $( DOCKER_TAG_ALPINE ) -build --target build $( BUILD_CONTEXT )
64- docker save $( DOCKER_TAG_ALPINE ) -build | gzip > $@
64+ .PHONY : build-ubuntu-build
65+ build-ubuntu-build : ubuntu .Dockerfile $( PLATFORM_TARBALLS )
66+ docker build --file ubuntu.Dockerfile -t $( TAG ) -build --target build $( BUILD_CONTEXT )
6567
6668alpine-84codes : # # Build and push docker build images based on the base images from 84codes
67- docker buildx build --build-arg crystal_version=$(CRYSTAL_VERSION ) -f alpine-84codes.Dockerfile --platform linux/amd64,linux/arm64 --tag crystallang/crystal: $( CRYSTAL_VERSION ) -alpine-84codes-build --push .
69+ docker buildx build --build-arg crystal_version=$(VERSION ) -f alpine-84codes.Dockerfile --platform linux/amd64,linux/arm64 --tag $( TAG ) -alpine-84codes-build --push .
6870
6971ubuntu-84codes : # # Build and push docker build images based on the base images from 84codes
70- docker buildx build --build-arg crystal_version=$(CRYSTAL_VERSION ) -f ubuntu-84codes.Dockerfile --platform linux/amd64,linux/arm64 --tag crystallang/crystal: $( CRYSTAL_VERSION ) -ubuntu-84codes-build --push .
72+ docker buildx build --build-arg crystal_version=$(VERSION ) -f ubuntu-84codes.Dockerfile --platform linux/amd64,linux/arm64 --tag $( TAG ) -ubuntu-84codes-build --push .
7173
7274.PHONY : smoke-all
7375smoke-all : # # Run smoke tests on all docker images
@@ -78,11 +80,10 @@ smoke-all: smoke-ubuntu-build
7880
7981.PHONY : smoke-%
8082smoke-% : # Run smoke tests on docker images
81- docker run --rm -v $(CURDIR ) /smoke.sh:/smoke.sh -e CRYSTAL_VERSION =$(CRYSTAL_VERSION ) $(DOCKER_REPOSITORY ) : $( DOCKER_TAG )$(subst -ubuntu,,-$* ) /smoke.sh $*
83+ docker run --rm -v $(CURDIR ) /smoke.sh:/smoke.sh -e VERSION =$(VERSION ) $(TAG )$(subst -ubuntu,,-$* ) /smoke.sh $*
8284
8385.PHONY : clean
84- clean : # # Clean up build and output directories
85- rm -Rf $(OUTPUT_DIR )
86+ clean : # # Clean up build context
8687 rm -Rf $(BUILD_CONTEXT )
8788
8889.PHONY : help
0 commit comments