Skip to content

Commit 20bd1ca

Browse files
committed
Makefile: Add diff and deploy
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent 1cca0b3 commit 20bd1ca

File tree

3 files changed

+92
-14
lines changed

3 files changed

+92
-14
lines changed

.github/workflows/diff.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Diff
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
diff:
8+
name: Diff
9+
runs-on: ubuntu-24.04
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Diff stable
15+
run: |
16+
make CHANNEL=stable diff
17+
18+
- name: Diff test
19+
run: |
20+
make CHANNEL=test diff
21+

Makefile

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,83 @@ SHELLCHECK=docker run --rm $(VOLUME_MOUNTS) -w /v koalaman/shellcheck:stable $(S
88

99
ENVSUBST_VARS=LOAD_SCRIPT_COMMIT_SHA
1010

11+
# Define the channels we want to build for
12+
CHANNELS=test stable
13+
14+
FILES=build/test/install.sh build/stable/install.sh build/stable/rootless-install.sh
15+
1116
.PHONY: build
12-
build: build/install.sh
17+
build: $(FILES)
1318

14-
build/install.sh: install.sh
19+
build/%/install.sh: install.sh
1520
mkdir -p $(@D)
16-
LOAD_SCRIPT_COMMIT_SHA='$(shell git rev-parse HEAD)' envsubst '$(addprefix $$,$(ENVSUBST_VARS))' < $< > $@
21+
sed 's/DEFAULT_CHANNEL_VALUE="stable"/DEFAULT_CHANNEL_VALUE="$*"/' $< | \
22+
LOAD_SCRIPT_COMMIT_SHA='$(shell git rev-parse HEAD)' envsubst '$(addprefix $$,$(ENVSUBST_VARS))' > $@
23+
24+
build/%/rootless-install.sh: rootless-install.sh
25+
mkdir -p $(@D)
26+
sed 's/DEFAULT_CHANNEL_VALUE="stable"/DEFAULT_CHANNEL_VALUE="$*"/' $< | \
27+
LOAD_SCRIPT_COMMIT_SHA='$(shell git rev-parse HEAD)' envsubst '$(addprefix $$,$(ENVSUBST_VARS))' > $@
1728

1829
.PHONY: shellcheck
19-
shellcheck: build/install.sh
20-
$(SHELLCHECK) $<
30+
shellcheck: $(FILES)
31+
$(SHELLCHECK) $^
2132

2233
.PHONY: test
23-
test: build/install.sh
24-
docker run --rm -i \
25-
$(VOLUME_MOUNTS) \
26-
-w /v \
27-
-e VERSION \
28-
-e CHANNEL \
29-
$(TEST_IMAGE) \
30-
sh "$<"
34+
test: $(foreach channel,$(CHANNELS),build/$(channel)/install.sh)
35+
for file in $^; do \
36+
(set -x; docker run --rm -it \
37+
$(VOLUME_MOUNTS) \
38+
--privileged \
39+
-e HOME=/tmp \
40+
-v /var/lib/docker \
41+
-w /v \
42+
-e VERSION \
43+
-e CHANNEL \
44+
$(TEST_IMAGE) \
45+
sh $$file) | tail -n 30; \
46+
done
47+
48+
AWS?=docker run \
49+
-v ./build:/build \
50+
-e AWS_ACCESS_KEY_ID \
51+
-e AWS_SECRET_ACCESS_KEY \
52+
-e AWS_SESSION_TOKEN \
53+
--rm -it amazon/aws-cli
54+
55+
.PHONY: deploy
56+
deploy: build/$(CHANNEL)/install.sh build/$(CHANNEL)/rootless-install.sh
57+
ifeq ($(S3_BUCKET),)
58+
$(error S3_BUCKET is empty.)
59+
endif
60+
ifeq ($(CF_DISTRIBUTION_ID),)
61+
$(error CF_DISTRIBUTION_ID is empty.)
62+
endif
63+
ifeq ($(CHANNEL),)
64+
$(error CHANNEL is empty.)
65+
endif
66+
$(AWS) s3 cp --acl public-read --content-type 'text/plain' /build/$(CHANNEL)/install.sh s3://$(S3_BUCKET)/index
67+
ifeq ($(CHANNEL),stable)
68+
$(AWS) s3 cp --acl public-read --content-type 'text/plain' /build/$(CHANNEL)/rootless-install.sh s3://$(S3_BUCKET)/rootless
69+
endif
70+
71+
$(AWS) cloudfront create-invalidation --distribution-id $(CF_DISTRIBUTION_ID) --paths '/*'
72+
73+
.PHONY: diff
74+
diff: TMP_DIR=/tmp
75+
diff: CHANNEL=stable
76+
diff: SUBDOMAIN=$(if $(filter test,$(CHANNEL)),test,$(if $(filter stable,$(CHANNEL)),get,$(error Invalid CHANNEL: $(CHANNEL))))
77+
diff: build/$(CHANNEL)/install.sh build/$(CHANNEL)/rootless-install.sh
78+
curl -sfSL https://$(SUBDOMAIN).docker.com -o $(TMP_DIR)/install.sh
79+
80+
echo "# Diff $(CHANNEL) install.sh"
81+
diff --color=always -u build/$(CHANNEL)/install.sh $(TMP_DIR)/install.sh || true
82+
83+
ifeq ($(CHANNEL),stable)
84+
curl -sfSL https://$(SUBDOMAIN).docker.com/rootless -o $(TMP_DIR)/rootless-install.sh
85+
echo "# Diff $(CHANNEL) rootless-install.sh"
86+
diff --color=always -u build/$(CHANNEL)/rootless-install.sh $(TMP_DIR)/rootless-install.sh || true
87+
endif
3188

3289
.PHONY: clean
3390
clean:

rootless-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ set -e
1616
#
1717
# Git commit from https://github.com/docker/docker-install when
1818
# the script was uploaded (Should only be modified by upload job):
19-
SCRIPT_COMMIT_SHA=UNKNOWN
19+
SCRIPT_COMMIT_SHA="$LOAD_SCRIPT_COMMIT_SHA"
2020

2121
# This script should be run with an unprivileged user and install/setup Docker under $HOME/bin/.
2222

0 commit comments

Comments
 (0)