From 1f18766f797ceb83cb0841fd134c634ef0491011 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Mon, 25 Mar 2024 16:02:52 -0500 Subject: [PATCH] build: Switch workflow to only use Makefile --- .gitignore | 3 ++- Makefile | 31 ++++++++++++++++++++++++++----- docker_push_script.sh | 16 ---------------- 3 files changed, 28 insertions(+), 22 deletions(-) delete mode 100755 docker_push_script.sh diff --git a/.gitignore b/.gitignore index 4fd7ce8..da49308 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # Ignore build outputs actix/target -.docker # Ignore SQLite file urls.sqlite @@ -8,3 +7,5 @@ urls.sqlite # Ignore irrelevant dotfiles .vscode/ **/.directory +.env + diff --git a/Makefile b/Makefile index c9a0555..9e87a43 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,40 @@ -USERNAME := ${DOCKER_USERNAME} +# .env file has the variables $DOCKER_USERNAME and $PASSWORD defined +include .env setup: cargo install cross + rustup target add x86_64-unknown-linux-musl docker buildx create --use --platform=linux/arm64,linux/amd64 --name multi-platform-builder docker buildx inspect --bootstrap -build: +build-dev: + cargo build --release --locked --manifest-path=actix/Cargo.toml --target x86_64-unknown-linux-musl + +docker-local: build-dev + docker build --tag chhoto-url --build-arg TARGETARCH=amd64 -f Dockerfile.multiarch . + +docker-test: docker-local + docker ps -q --filter "name=chhoto-url" | xargs -r docker stop + docker ps -aq --filter "name=chhoto-url" | xargs -r docker rm + docker run -p 4567:4567 --name chhoto-url -e password="${PASSWORD}" -d chhoto-url + docker logs chhoto-url -f + +docker-dev: build-dev + docker build --push --tag ${DOCKER_USERNAME}:chhoto-url:dev --build-arg TARGETARCH=amd64 -f Dockerfile.multiarch . + +build-release: cross build --release --locked --manifest-path=actix/Cargo.toml --target aarch64-unknown-linux-musl cross build --release --locked --manifest-path=actix/Cargo.toml --target armv7-unknown-linux-musleabihf cross build --release --locked --manifest-path=actix/Cargo.toml --target x86_64-unknown-linux-musl -docker: build - docker buildx build --push --tag ${USERNAME}/chhoto-url:dev --platform linux/amd64,linux/arm64,linux/arm/v7 -f Dockerfile.multiarch . +V_PATCH := $(shell cat actix/Cargo.toml | sed -rn 's/^version = "(.+)"$$/\1/p') +V_MINOR := $(shell cat actix/Cargo.toml | sed -rn 's/^version = "(.+)\..+"$$/\1/p') +V_MAJOR := $(shell cat actix/Cargo.toml | sed -rn 's/^version = "(.+)\..+\..+"$$/\1/p') +docker-release: build-release + docker buildx build --push --tag ${DOCKER_USERNAME}/chhoto-url:${V_MAJOR} --tag ${DOCKER_USERNAME}/chhoto-url:${V_MINOR} --tag ${DOCKER_USERNAME}/chhoto-url:${V_PATCH} \ + ---tag ${DOCKER_USERNAME}/chhoto-url:latest -platform linux/amd64,linux/arm64,linux/arm/v7 -f Dockerfile.multiarch . clean: cargo clean --manifest-path=actix/Cargo.toml -.PHONY: build +.PHONY: build-dev docker-local build-release diff --git a/docker_push_script.sh b/docker_push_script.sh deleted file mode 100755 index 7a1787b..0000000 --- a/docker_push_script.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/env bash - -if [ "$1" == "dev" ]; then - docker buildx build --push --tag sintan1729/$name:dev . - -elif [ "$1" == "release" ]; then - v_patch=$(cat actix/Cargo.toml | sed -rn 's/^version = "(.+)"$/\1/p') - v_minor=$(echo $v_patch | sed -rn 's/^(.+\..+)\..+$/\1/p') - v_major=$(echo $v_minor | sed -rn 's/^(.+)\..+$/\1/p') - - make build - name="chhoto-url" - docker buildx build --push --tag sintan1729/$name:$v_major --tag sintan1729/$v_minor: \ - --tag sintan1729/$name:$v_patch --tag sintan1729/$name:latest --platform linux/amd64,linux/arm64,linux/arm/v7 -f Dockerfile.multiarch . -fi -