forked from cfug/dart.cn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
128 lines (107 loc) · 3.46 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/make -f
-include .env
all: clean up down debug shell serve test-build test-run setup \
serve emulate stage test build-image build deploy deploy-ci \
fetch-sums test-builds test-run
.PHONY: all
.DEFAULT_GOAL := up
# NOTE all vars can be overridden by using a local .env file
BUILD_COMMIT := $(shell git rev-parse --short HEAD)
BUILD_CONFIGS ?= _config.yml
BUILD_NAME ?= dart_dev_build
BUILD_TAG ?= dart-dev
BUILD_TARGET ?= build
DART_CHANNEL ?= stable
DART_VERSION ?= latest
FIREBASE_PROJECT ?= default
FIREBASE_CHANNEL ?= dart
JEKYLL_SITE_HOST ?= 0.0.0.0
JEKYLL_SITE_PORT ?= 4000
# Here so Docker Compose does not complain, add any env
# overrides to this file. Blank is okay, it's ignored.
# For example, add a FIREBASE_PROJECT if staging
.env:
touch $@
# Clean up caches, build files, etc
clean:
rm -rf _site **/.jekyll* *.log tmp .dart_tool
# Start local dev container/server
up:
docker compose up site
# Bring down the local dev container/server
down:
-docker compose down site
# Run the dev container and enter shell for debugging
run:
docker compose run --rm site bash
# Enter the shell of the running container from `make up`
exec:
-docker compose exec site bash
# Reset, build dev container from scratch
setup:
make clean
-docker compose down
-docker rmi ${BUILD_TAG}:${DART_CHANNEL}
docker compose build --no-cache site
# Serve the Jekyll site with livereload and incremental builds
serve:
bundle exec jekyll serve \
--host ${JEKYLL_SITE_HOST} \
--port ${JEKYLL_SITE_PORT} \
--config _config.yml,_config_dev.yml \
--livereload \
--incremental \
--trace
# Run all tests inside a built container
test:
DOCKER_BUILDKIT=1 docker build \
-t dart-tests:${DART_CHANNEL} \
--target dart-tests \
--build-arg DART_VERSION=${DART_VERSION} \
--build-arg DART_CHANNEL=${DART_CHANNEL} .
docker run --rm -v ${PWD}:/app dart-tests:${DART_CHANNEL}
# Build docker image with optional target
# Usage: `make build-image [BUILD_CONFIGS=<config1,[config2,]>]`
build-image:
DOCKER_BUILDKIT=1 docker build \
-t ${BUILD_TAG}:${BUILD_COMMIT} \
--no-cache \
--target ${BUILD_TARGET} \
--build-arg DART_VERSION=${DART_VERSION} \
--build-arg DART_CHANNEL=${DART_CHANNEL} \
--build-arg BUILD_CONFIGS=${BUILD_CONFIGS} .
# Build the Jekyll site via Docker and copy built site to local
build:
make clean
make build-image
docker run --rm -d --name ${BUILD_NAME} -t ${BUILD_TAG}:${BUILD_COMMIT}
docker cp ${BUILD_NAME}:/app/_site _site
docker stop ${BUILD_NAME}
docker rmi -f ${BUILD_TAG}:${BUILD_COMMIT}
# Overwrite robots.txt with production version
write-prod-robots:
@echo "User-agent: *\nDisallow:\n\nSitemap: https://dart.cn/sitemap.xml" \
> _site/robots.txt
# Deploy locally
deploy:
sh tool/translator/deploy-cn.sh
################## UTILS ##################
# Fetch SDK sums for current Dart SDKs by arch, Node PPA
# This outputs a bash case format to be copied to Dockerfile
fetch-sums:
tool/fetch-dart-sdk-sums.sh \
--version ${DART_VERSION} \
--channel ${DART_CHANNEL}
tool/fetch-node-ppa-sum.sh
# Test the dev container with pure docker
test-builds:
docker build -t ${BUILD_TAG}:stable \
--no-cache --target=dart-tests .
docker build -t ${BUILD_TAG}:beta \
--no-cache --target=dart-tests --build-arg DART_CHANNEL=beta .
docker build -t ${BUILD_TAG}:dev \
--no-cache --target=dart-tests --build-arg DART_CHANNEL=dev .
# Test stable run with volume
TEST_CHANNEL =? stable
test-run:
docker run --rm -it -v ${PWD}:/app ${BUILD_TAG}:${TEST_CHANNEL} bash