fork/static-web-server
git clone https://git.julia.blue/fork/static-web-server
8451cf7
allow-symlink
1PKG_TARGET = x86_64-unknown-linux-musl 2PKG_TARGET_DARWIN = x86_64-apple-darwin 3RUST_VERSION ?= $( shell rustc --version | cut -d ' ' -f2 ) 4 5PKG_BIN_PATH = ./bin 6PKG_TMP_PATH = /tmp 7 8PKG_NAME =$( shell cat Cargo.toml| sed -n 's/name = "\([^}]*\)"/\1/p' | head -n1 ) 9PKG_TAG =$( shell cat Cargo.toml| sed -n 's/version = "\([^}]*\)"/\1/p' | head -n1 ) 10 11PKG_RELEASE_NAME =$( PKG_NAME ) -v$( PKG_TAG ) -$( PKG_TARGET ) 12PKG_RELEASE_NAME_DARWIN =$( PKG_NAME ) -v$( PKG_TAG ) -$( PKG_TARGET_DARWIN ) 13 14PKG_TMP_BIN_PATH =$( PKG_TMP_PATH ) /$( PKG_RELEASE_NAME ) 15PKG_TMP_BIN_PATH_DARWIN =$( PKG_TMP_PATH ) /$( PKG_RELEASE_NAME_DARWIN ) 16 17####################################### 18############# Development ############# 19####################################### 20 21install : 22@ rustup target add$( PKG_TARGET ) 23@ cargo install--force cargo-make 24@ cargo install cargo-audit 25.PHONY : install 26 27lint : 28@ rustc -vV 29@ cargo clippy--all-features -- -D warnings 30.PHONY : lint 31 32build : 33@ rustc -vV 34@ cargo build--release --target $( PKG_TARGET ) 35.PHONY : build 36 37# Release test tasks 38test.release : 39@ docker run--rm -it \ 40-v $( PWD ) :/root/src/static-web-server \ 41-v cargo-git:/root/.cargo/git \ 42-v cargo-registry:/root/.cargo/registry \ 43-v cargo-target:/root/src/static-web-server/target \ 44\ 45--workdir /root/src/static-web-server \ 46 joseluisq/rust-linux-darwin-builder:$( RUST_VERSION ) \ 47\ 48 bash-c "make prod.release" 49.PHONY : test.release 50 51linux : 52@ docker run--rm -it \ 53-v $( PWD ) :/root/src/static-web-server \ 54-v cargo-git:/root/.cargo/git \ 55-v cargo-registry:/root/.cargo/registry \ 56-v cargo-target:/root/src/static-web-server/target \ 57\ 58--workdir /root/src/static-web-server \ 59 joseluisq/rust-linux-darwin-builder:$( RUST_VERSION ) \ 60\ 61 bash-c "\ 62echo Building Linux release binary... && \ 63rustc -vV && \ 64cargo build --release --target $( PKG_TARGET ) && \ 65du -sh ./target/ $( PKG_TARGET ) /release/ $( PKG_NAME ) && \ 66mkdir -p release && \ 67cp -rf ./target/ $( PKG_TARGET ) /release/ $( PKG_NAME ) release/ $( PKG_NAME ) -linux && \ 68echo \"Shrinking Linux binary file...\" && \ 69strip release/ $( PKG_NAME ) -linux && \ 70du -sh ./release/ $( PKG_NAME ) -linux" 71.PHONY : linux 72 73darwin : 74@ docker run--rm -it \ 75-v $( PWD ) :/root/src/static-web-server \ 76-v cargo-git:/root/.cargo/git \ 77-v cargo-registry:/root/.cargo/registry \ 78-v cargo-target:/root/src/static-web-server/target \ 79\ 80--workdir /root/src/static-web-server \ 81 joseluisq/rust-linux-darwin-builder:$( RUST_VERSION ) \ 82\ 83 bash-c "\ 84echo Building Darwin release binary... && \ 85rustc -vV && \ 86env CC=o64-clang CXX=o64-clang++ cargo build --release --target $( PKG_TARGET_DARWIN ) && \ 87du -sh ./target/ $( PKG_TARGET_DARWIN ) /release/ $( PKG_NAME ) && \ 88mkdir -p release && \ 89cp -rf ./target/ $( PKG_TARGET_DARWIN ) /release/ $( PKG_NAME ) release/ $( PKG_NAME ) -darwin && \ 90echo \"Shrinking Darwin binary file...\" && \ 91x86_64-apple-darwin20.2-strip release/ $( PKG_NAME ) -darwin && \ 92du -sh ./release/ $( PKG_NAME ) -darwin" 93.PHONY : darwin 94 95####################################### 96########### Utility tasks ############# 97####################################### 98 99test : 100@ echo "Testing application..." 101@ rustc -vV 102@ cargo test 103.PHONY : test 104 105fmt : 106@ cargo fix 107@ cargo fmt--all 108.PHONY : fmt 109 110## Development Docker images 111 112docker.image : 113@ echo "Creating development Docker Scratch image..." 114@ cp -frp ./target/x86_64-unknown-linux-musl/release/static-web-server ./docker/devel/ 115@ docker build \ 116--rm=true -f ./docker/devel/Dockerfile.scratch \ 117--platform= "linux/x86_64" \ 118--network= "host" \ 119-t joseluisq/${ PKG_NAME } :devel .--pull=true 120.PHONY : docker.image 121 122docker.image.alpine : 123@ echo "Creating development Docker Alpine image..." 124@ cp -frp ./target/x86_64-unknown-linux-musl/release/static-web-server ./docker/devel/ 125@ docker build \ 126--rm=true -f ./docker/devel/Dockerfile.alpine \ 127--platform= "linux/x86_64" \ 128--network= "host" \ 129-t joseluisq/${ PKG_NAME } :devel-alpine .--pull=true 130.PHONY : docker.image.alpine 131 132docker.image.debian : 133@ echo "Creating development Docker Debian image..." 134@ cp -frp ./target/release/static-web-server ./docker/devel/ 135@ docker build \ 136--platform= "linux/x86_64" \ 137--network= "host" \ 138--rm=true -f ./docker/devel/Dockerfile.debian \ 139-t joseluisq/${ PKG_NAME } :devel-debian .--pull=true 140.PHONY : docker.image.debian 141 142buildx.image.debian : 143docker buildx build \ 144--platform= "linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/arm/v6,linux/ppc64le,linux/s390x" \ 145--network= "host" \ 146--build-arg SERVER_VERSION=2.39.0 \ 147--rm=true -f ./docker/debian/Dockerfile \ 148-t joseluisq/${ PKG_NAME } :devel-debian .--pull=true 149# --push \ 150.PHONY: buildx.image.debian 151 152docker.image.all : 153@ make docker.image 154@ make docker.image.alpine 155@ make docker.image.debian 156.PHONY : docker.image.all 157 158 159####################################### 160########## Production tasks ########### 161####################################### 162 163# Compile release binary 164define build_release = 165 set -e 166 set -u 167 168 echo 169 echo "Compiling application..." 170 rustc -vV 171 echo 172 echo "Compiling release binary for $(PKG_TARGET)..." 173 cargo build --release --target $(PKG_TARGET) 174 echo 175 echo 176 echo "Compiling release binary for $(PKG_TARGET_DARWIN)..." 177 env CC=o64-clang CXX=o64-clang++ cargo build --release --target $(PKG_TARGET_DARWIN) 178 echo 179 echo "Release builds were compiled!" 180endef 181 182# Shrink a release binary size 183define build_release_shrink = 184 set -e 185 set -u 186 187 echo "Copying release binaries..." 188 189 mkdir -p $(PKG_BIN_PATH) 190 191 # Linux 192 mkdir -p $(PKG_TMP_BIN_PATH) 193 cp -rf ./target/$(PKG_TARGET)/release/$(PKG_NAME) $(PKG_TMP_BIN_PATH)/ 194 195 # Darwin 196 mkdir -p $(PKG_TMP_BIN_PATH_DARWIN) 197 cp -rf ./target/$(PKG_TARGET_DARWIN)/release/$(PKG_NAME) $(PKG_TMP_BIN_PATH_DARWIN)/ 198 199 # Linux 200 echo "Performing Linux/Darwin binaries shrinking..." 201 echo "Binary sizes before:" 202 du -sh $(PKG_TMP_BIN_PATH)/$(PKG_NAME) 203 du -sh $(PKG_TMP_BIN_PATH_DARWIN)/$(PKG_NAME) 204 205 # Shrink binaries in place (tmp dir) 206 strip $(PKG_TMP_BIN_PATH)/$(PKG_NAME) 207 x86_64-apple-darwin20.2-strip $(PKG_TMP_BIN_PATH_DARWIN)/$(PKG_NAME) 208 209 echo "Binary sizes after (shrinking):" 210 du -sh $(PKG_TMP_BIN_PATH)/$(PKG_NAME) 211 du -sh $(PKG_TMP_BIN_PATH_DARWIN)/$(PKG_NAME) 212 213 # Copy only Linux binary for the Docker image build process 214 echo "Copying Linux binary from $(PKG_TMP_BIN_PATH) to $(PKG_BIN_PATH) directory..." 215 cp -rf $(PKG_TMP_BIN_PATH)/$(PKG_NAME) $(PKG_BIN_PATH)/ 216 217 echo "Releases size shrinking completed!" 218endef 219 220# Creates release files (tarballs, zipballs) 221define build_release_files = 222 set -e 223 set -u 224 225 echo "Creating tarballs with their checksums..." 226 227 # Enter to bin/ directory 228 mkdir -p $(PKG_BIN_PATH) 229 cd $(PKG_BIN_PATH) 230 pwd 231 232 # Tar/Gzip/sha256sum file for Linux 233 tar czvf $(PKG_RELEASE_NAME).tar.gz -C $(PKG_TMP_BIN_PATH) $(PKG_NAME) 234 sha256sum $(PKG_RELEASE_NAME).tar.gz > $(PKG_NAME)-v$(PKG_TAG)-SHA256SUM 235 echo "Linux tarball with sha256sum created." 236 237 # Tar/Gzip/sha256sum file for Darwin 238 tar czvf $(PKG_RELEASE_NAME_DARWIN).tar.gz -C $(PKG_TMP_BIN_PATH_DARWIN) $(PKG_NAME) 239 sha256sum $(PKG_RELEASE_NAME_DARWIN).tar.gz >> $(PKG_NAME)-v$(PKG_TAG)-SHA256SUM 240 echo "Darwin tarball with sha256sum created." 241 242 du -sh ./* 243 echo "Release tarballs and sha256sum files created!" 244endef 245 246prod.release : 247set -e 248set -u 249 250echo "Building a release..." 251 252$( build_release ) 253$( build_release_shrink ) 254$( build_release_files ) 255.ONESHELL : prod.release 256 257prod.release.build : 258@ $( build_release ) 259.ONESHELL : prod.release.build 260 261prod.release.shrink : 262@ $( build_release_shrink ) 263.ONESHELL : prod.release.shrink 264 265prod.release.files : 266@ $( build_release_files ) 267.ONESHELL : prod.release.files 268 269prod.release.version : 270git add . 271git commit .-m "v $( PKG_TAG ) " 272git tag v$( PKG_TAG ) 273git push 274.ONESHELL : prod.release.version 275 276docs-dev : 277@ docker-compose -f docs/docker-compose.yml up--build 278.PHONY : docs-dev 279 280crate-docs : 281@ cargo doc--no-deps 282.PHONY : crate-docs 283 284crate-docs-dev : 285@ env \ 286 RUSTDOCFLAGS="--cfg docsrs" \ 287 cargo doc--lib --no-deps --all-features --document-private-items 288@ echo "Crate documentation: http://localhost:8787/static_web_server" 289@ static-web-server -p 8787-d target/doc/ \ 290 &watchman-make -p 'src/**/*.rs' --run '\ 291env \ 292RUSTDOCFLAGS="--cfg docsrs" \ 293cargo doc --lib --no-deps --all-features --document-private-items' 294.PHONY : crate-docs-dev 295 296docs-deploy : 297@ git stash 298@ rm -rf /tmp/docs 299@ mkdir -p /tmp/docs 300@ docker-compose -f docs/docker-compose.yml build 301@ docker run-it --rm \ 302-v $( PWD ) /.git:/docs/.git \ 303-v $( PWD ) /docs/content:/docs/docs/content \ 304-v $( PWD ) /docs/mkdocs.yml:/docs/mkdocs.yml \ 305-v /tmp/docs:/tmp/docs \ 306 static-web-server-docs mkdocs build 307@ git checkout gh-pages 308@ git clean-fdx 309@ rm -rf docs/ 310@ mkdir -p docs/ 311@ cp -rf /tmp/docs/. docs/ 312@ git add docs/ 313@ git commit docs/-m "docs: automatic documentation updates [skip ci]" 314@ git push origin gh-pages 315@ git push github gh-pages 316@ echo 317@ echo "Documentation built and published" 318@ git checkout master 319.PHONY : docs-deploy 320 321typos : 322@ typos .--config ./.github/workflows/config/typos.toml 323.PHONY : typos 324 325docs-format : 326@ uvx --python ">=3.13" --with mdformat-mkdocs mdformat ./*.md docs/ 327.ONESHELL : docs-format 328 329man : 330@ asciidoctor --doctype=manpage --backend=manpage docs/man/static-web-server.1.rst 331.PHONY : man