Skip to content

Commit e3a518e

Browse files
authored
Merge pull request #1 from grimzy/args-in-build
Build Images with --build-args
2 parents 65bc48a + 66b1384 commit e3a518e

30 files changed

+372
-237
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.idea/
1+
.idea/
2+
scripts/

CHANGELOG.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
This project adheres to [Semantic Versioning][semver].
5+
6+
7+
## \[Unreleased]
8+
9+
Refer to master branch
10+
11+
## \[v1.1.0\] - 2019-10-12
12+
13+
### Build Images with --build-args:
14+
- Using Docker Cloud `build` hook to pass `--build-args` to our `docker build` command during Automated Builds
15+
- Using Docker Cloud `pre_push` hook to push our new image tags during Automated Builds
16+
- Only generating scripts when calling make scripts (scripts are Git ignored)
17+
- Updated script templates
18+
- Removed generated files
19+
20+
## \[v1.0.1\] - 2018-06-16
21+
22+
### PHP 7.2, symlinks:
23+
- Added PHP 7.2
24+
- Prepending image variant to image name
25+
- Added symklink alternative to copying the binaries
26+
- Fixed composer volume mount in readme and templates
27+
- Generated build files for `v1.0.1`
28+
29+
## \[v1.0.0\] - 2017-08-26
30+
31+
### Initial Release:
32+
- Added build generation from templates
33+
- Generated build files for `v1.0.0`
34+
- Initial working Docker build
35+
36+
[semver]: https://semver.org/spec/v2.0.0.html "Semantic Versioning 2.0.0"
37+

Makefile

+83-47
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,98 @@
1-
VERSION=1.0.1
2-
VERSIONS=5.5 5.6 7.0 7.1 7.2
3-
GENERATED_DIR=generated
4-
BUILDS_DIR=$(GENERATED_DIR)/builds
5-
BINS_DIR=$(GENERATED_DIR)/bins
1+
# SOURCE_BRANCH
2+
SOURCE_BRANCH=1.1.0
3+
4+
# Possible versions: 5.5 5.6 7.0 7.1 7.2
5+
PHP_VERSIONS=5.5 5.6 7.0 7.1 7.2
6+
7+
# Possible VARIANT: cli, fpm, apache, alpine
8+
PHP_VARIANTS=cli
9+
610
BIN_DIR=/usr/local/bin
11+
SCRIPTS_DIR=scripts
12+
13+
.PHONY: build
14+
build:
15+
@{ \
16+
for php_version in $(PHP_VERSIONS); do \
17+
xdebug_version=; \
18+
if [ $$php_version == "5.5" ] || [ $$php_version == "5.6" ]; then \
19+
xdebug_version=-2.5.5; \
20+
fi; \
21+
for php_variant in $(PHP_VARIANTS); do \
22+
image_name=jestefane/php-dev:$$php_version-$$php_variant-$(SOURCE_BRANCH); \
23+
echo Building image: $$image_name; \
24+
docker build \
25+
-t $$image_name \
26+
--build-arg BUILD_PHP_VERSION=$$php_version \
27+
--build-arg BUILD_PHP_VARIANT=$$php_variant \
28+
--build-arg BUILD_XDEBUG_VERSION=$$xdebug_version build; \
29+
done; \
30+
done; \
31+
}
732

8-
builds: templates
33+
.PHONY: rm_build
34+
rm_build:
935
@{ \
10-
for version in $(VERSIONS); \
11-
do \
12-
cli=jestefane/php-dev:$$version-cli-$(VERSION); \
13-
echo Building $$cli; \
14-
docker build -t $$cli $(BUILDS_DIR)/$$version-cli; \
36+
for php_version in $(PHP_VERSIONS); do \
37+
for php_variant in $(PHP_VARIANTS); do \
38+
image_name=jestefane/php-dev:$$php_version-$$php_variant-$(SOURCE_BRANCH); \
39+
echo Removing image: $$image_name; \
40+
docker rmi $$image_name || true; \
41+
done; \
1542
done; \
1643
}
1744

18-
rm_images:
45+
.PHONY: rebuild
46+
rebuild: rm_build build
47+
48+
.PHONY: scripts
49+
scripts: rm_scripts_dir
1950
@{ \
20-
for version in $(VERSIONS); \
21-
do \
22-
cli=jestefane/php-dev:$$version-cli-$(VERSION); \
23-
docker rmi $$cli || true; \
51+
for php_version in $(PHP_VERSIONS); do \
52+
echo "Generating scripts for PHP VERSION: $$php_version"; \
53+
for php_variant in $(PHP_VARIANTS); do \
54+
regex=s!%%PHP_VERSION%%!$$php_version!g\;s!%%PHP_VARIANT%%!$$php_variant!g\;s!%%SOURCE_BRANCH%%!$(SOURCE_BRANCH)!g; \
55+
mkdir -p $(SCRIPTS_DIR); \
56+
echo ">>> Script: PHP $$php_version-$$php_variant"; \
57+
sed $$regex template/php-cli.template > $(SCRIPTS_DIR)/php-$$php_version-$$php_variant; \
58+
done; \
59+
echo ">>> Script Composer $$php_version"; \
60+
sed $$regex template/composer.template > $(SCRIPTS_DIR)/composer-$$php_version; \
2461
done; \
2562
}
2663

27-
rebuild: rm_images builds
64+
.PHONY: rm_scripts_dir
65+
rm_scripts_dir:
66+
@echo Deleting previously generated scripts directory
67+
@rm -Rf $(SCRIPTS_DIR)
2868

29-
templates: rm_templates
69+
.PHONY: shortcuts
70+
shortcuts: scripts
71+
@chmod +x $(SCRIPTS_DIR)/*
72+
@cd $(SCRIPTS_DIR)
73+
@$(eval DIR := ${CURDIR}/$(SCRIPTS_DIR))
74+
@ln -s $(DIR)/* $(BIN_DIR) || true
75+
@echo Symlink scripts from $(DIR) into $(BIN_DIR)
76+
77+
.PHONY: rm_shortcuts
78+
rm_shortcuts:
3079
@{ \
31-
for version in $(VERSIONS); \
32-
do \
33-
echo Building for PHP $$version; \
34-
regex=s!%%PHP_VERSION%%!$$version!g\;s!%%IMAGE_VERSION%%!$(VERSION)!g; \
35-
version_dir=$(BUILDS_DIR)/$$version; \
36-
mkdir -p $$version_dir-cli; \
37-
sed $$regex template/Dockerfile-cli.template > $$version_dir-cli/Dockerfile; \
38-
cp template/php.ini $$version_dir-cli; \
39-
echo ... Dockerfile; \
40-
mkdir -p $(BINS_DIR); \
41-
sed $$regex template/php-cli.template > $(BINS_DIR)/php-cli-$$version; \
42-
echo ... php-cli bin; \
43-
sed $$regex template/composer.template > $(BINS_DIR)/composer-$$version; \
44-
echo ... composer bin; \
80+
for php_version in $(PHP_VERSIONS); do \
81+
echo "Uninstalling scripts from $(BIN_DIR) for PHP VERSION $$php_version"; \
82+
for php_variant in $(PHP_VARIANTS); do \
83+
echo ">>> Uninstalled script: PHP $$php_version-$$php_variant"; \
84+
rm $(BIN_DIR)/php-$$php_version-$$php_variant || true; \
85+
done; \
86+
echo ">>> Uninstalled script: Composer $$php_version from $(BIN_DIR)"; \
87+
rm $(BIN_DIR)/composer-$$php_version || true; \
4588
done; \
4689
}
4790

48-
rm_templates:
49-
@echo Deleting generated templates
50-
@rm -Rf $(GENERATED_DIR)
51-
52-
cp_bins:
53-
@chmod +x $(BINS_DIR)/*
54-
@cp $(BINS_DIR)/* $(BIN_DIR)
55-
@echo Copied bins into $(BIN_DIR)
56-
57-
symlink_bins:
58-
@chmod +x $(BINS_DIR)/*
59-
@cd $(BINS_DIR)
60-
@$(eval DIR := ${CURDIR}/$(BINS_DIR))
61-
@ln -s $(DIR)/* $(BIN_DIR)
62-
@echo Symlink bins from $(DIR) into $(BIN_DIR)
91+
.PHONY: rm_dangling
92+
rm_dangling:
93+
@echo Removing dangling volumes
94+
@docker volume ls -qf dangling=true | xargs docker volume rm
95+
@echo Removing dangling images
96+
@docker images -qf dangling=true | xargs docker rmi
97+
98+
#TODO: aliasing shortcuts to get the defaults php php-fpm and composer

0 commit comments

Comments
 (0)