diff --git a/Makefile.toml b/Makefile.toml index 96ed347..982267e 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -6,105 +6,6 @@ skip_core_tasks = true script = ''' #!@duckscript -exec docker-compose -p hikari -f ./tasks/compose.yml build -''' - -[tasks.build-native] -script = ''' -#!@duckscript - -# TODO - Move the wasm build to docker container -# TODO - Check the version of wasm-bindgen-cli, and if it's not 0.2.87, install it -# exec cargo install -f wasm-bindgen-cli --version 0.2.87 exec cargo build --package hikari-web --target wasm32-unknown-unknown --release -exec wasm-bindgen --target no-modules --no-modules-global __wasm_vendor_entry --out-dir ./target/dist --out-name a --no-typescript ./target/wasm32-unknown-unknown/release/hikari_web.wasm - -html_raw = set "
" -writefile ./packages/app/res/index.html ${html_raw} -cp ./target/dist/a.js ./packages/app/res/a.js -cp ./target/dist/a_bg.wasm ./packages/app/res/a.wasm - -exec cargo build --package hikari-app -''' - -[tasks.up] -script = ''' -#!@duckscript - -db_username = get_env DB_USERNAME -if is_empty ${db_username} - echo "DB_USERNAME is not set" - exit 1 -end - -db_password = get_env DB_PASSWORD -if is_empty ${db_password} - echo "DB_PASSWORD is not set" - exit 1 -end - -set_env DB_DATABASE "hikari" - -exec docker-compose -p hikari -f ./tasks/compose.yml up --build -d -''' - -[tasks.dev-on-container-reboot] -condition = { profiles = ["docker-inside"] } -script = ''' -#!@duckscript - -cd /home -while not is_path_exists /home/a - echo "Waiting for build..." - sleep 1000 -end -exec /home/a -''' - -[tasks.dev-on-container-build] -condition = { profiles = ["docker-inside"] } -script = ''' -#!@duckscript - -cd /home -if is_path_exists /home/target/Cargo.lock - cp /home/target/Cargo.lock /home/Cargo.lock -end -exec cargo check -cp /home/Cargo.lock /home/target/Cargo.lock - -exec cargo build --package hikari-web --target wasm32-unknown-unknown -cd /home/target/wasm32-unknown-unknown/debug -exec wasm-bindgen --out-dir /home/dist --out-name a --target no-modules --no-typescript --no-modules-global __wasm_vendor_entry hikari_web.wasm - -cd /home -exec cargo build --package hikari-router - -mkdir /home/res -cp /home/packages/router/res/favicon.ico /home/res/favicon.ico -cp /home/packages/router/res/logo.png /home/res/logo.png - -mv /home/dist/a_bg.wasm /home/res/a.wasm -mv /home/dist/a.js /home/res/a.js -cp /home/target/debug/hikari-router /home/a - -cd /home -exec /home/a -''' - -[tasks.dev-preload] -env = { DB_USERNAME = "homo", DB_PASSWORD = "1145141919810", DB_DATABASE = "hikari" } -script = ''' -#!@duckscript - -exec docker-compose -p hikari-dev -f ./tasks/compose.dev.yml up --build -d -''' - -[tasks.dev] -dependencies = [{ name = "dev-preload" }] -watch = { postpone = true, no_git_ignore = true, ignore_pattern = "Cargo.lock", watch = ["./packages/"] } -script = ''' -#!@duckscript - -exec docker-compose -p hikari-dev -f ./tasks/compose.dev.yml restart dynamic +exec wasm-bindgen --out-dir ./target/wasm32-html --out-name a --target no-modules --no-typescript --no-modules-global __wasm_vendor_entry ./target/wasm32-unknown-unknown/release/hikari_web.wasm ''' diff --git a/tasks/build.dockerfile b/tasks/build.dockerfile deleted file mode 100644 index 5cb98fd..0000000 --- a/tasks/build.dockerfile +++ /dev/null @@ -1,62 +0,0 @@ -# Preload dependencies, -# used to speed up repeated builds and reduce traffic consumption of libraries -FROM rust:latest as stage-deps - -RUN rustup target add wasm32-unknown-unknown -RUN cargo install cargo-make -RUN cargo install wasm-bindgen-cli@0.2.87 - -COPY ./Cargo.toml /home/Cargo.toml -RUN cargo new --lib --name hikari-database /home/packages/database -COPY ./packages/database/Cargo.toml /home/packages/database/Cargo.toml -RUN cargo new --name hikari-router /home/packages/router -COPY ./packages/router/Cargo.toml /home/packages/router/Cargo.toml -RUN cargo new --lib --name hikari-web /home/packages/web -COPY ./packages/web/Cargo.toml /home/packages/web/Cargo.toml -RUN cargo new --lib --name hikari-utils /home/packages/utils -COPY ./packages/utils/Cargo.toml /home/packages/utils/Cargo.toml - -WORKDIR /home -RUN cargo fetch - -COPY ./packages/database /home/packages/database -COPY ./packages/router /home/packages/router -COPY ./packages/web /home/packages/web -COPY ./packages/utils /home/packages/utils - -# Stage 1 for client build, used to compile wasm file -FROM stage-deps as stage-client-build1 - -WORKDIR /home -RUN cargo build --offline --package hikari-web --target wasm32-unknown-unknown --release - -# Stage 2 for client build, used to process wasm file for browser platform -FROM stage-deps as stage-client-build2 - -COPY --from=stage-client-build1 /home/target/wasm32-unknown-unknown/release/hikari_web.wasm /home/a.wasm -WORKDIR /home -RUN wasm-bindgen\ - --out-dir /home/dist\ - --out-name a\ - --target no-modules\ - --no-typescript\ - --no-modules-global __wasm_vendor_entry\ - a.wasm - -# Stage 1 for server build, used to compile server program -FROM stage-deps as stage-server-build1 - -WORKDIR /home -RUN cargo build --offline --package hikari-router --release - -# Stage 2 for server build, used to integrate the build result of client and generate the final image -FROM ubuntu:22.10 as stage-server-build2 - -COPY ./packages/router/res /home/res -COPY --from=stage-client-build2 /home/dist/a_bg.wasm /home/res/a.wasm -COPY --from=stage-client-build2 /home/dist/a.js /home/res/a.js -COPY --from=stage-server-build1 /home/target/release/hikari-router /home/a -ENV ROOT_DIR=/home/res -WORKDIR /home -ENTRYPOINT [ "./a" ] -EXPOSE 80 diff --git a/tasks/compose.dev.yml b/tasks/compose.dev.yml deleted file mode 100644 index 52ed943..0000000 --- a/tasks/compose.dev.yml +++ /dev/null @@ -1,45 +0,0 @@ -version: '3' - -volumes: - db-dev: - build-cache: - -services: - dynamic: - build: - context: ../ - dockerfile: ./tasks/dev.dockerfile - ports: - - 80:80 - volumes: - - ../packages/database:/home/packages/database - - ../packages/router:/home/packages/router - - ../packages/utils:/home/packages/utils - - ../packages/web:/home/packages/web - - build-cache:/home/target - environment: - - DB_HOST=database - - DB_USERNAME=$DB_USERNAME - - DB_PASSWORD=$DB_PASSWORD - - DB_DATABASE=$DB_DATABASE - networks: - - backend-dev - depends_on: - - database - database: - image: mariadb:lts - ports: - - 3306:3306 - volumes: - - db-dev:/var/lib/mysql - environment: - - MARIADB_USER=$DB_USERNAME - - MARIADB_PASSWORD=$DB_PASSWORD - - MARIADB_DATABASE=$DB_DATABASE - - MARIADB_RANDOM_ROOT_PASSWORD=yes - networks: - - backend-dev - -networks: - backend-dev: - driver: bridge diff --git a/tasks/compose.yml b/tasks/compose.yml deleted file mode 100644 index d84a612..0000000 --- a/tasks/compose.yml +++ /dev/null @@ -1,40 +0,0 @@ -version: '3' - -volumes: - db: - -services: - dynamic: - build: - context: ../ - dockerfile: ./tasks/build.dockerfile - ports: - - 80:80 - environment: - - DB_HOST=database - - DB_USERNAME=$DB_USERNAME - - DB_PASSWORD=$DB_PASSWORD - - DB_DATABASE=$DB_DATABASE - networks: - - backend - restart: always - depends_on: - - database - database: - image: mariadb:lts - expose: - - 3306 - volumes: - - db:/var/lib/mysql - environment: - - MARIADB_USER=$DB_USERNAME - - MARIADB_PASSWORD=$DB_PASSWORD - - MARIADB_DATABASE=$DB_DATABASE - - MARIADB_RANDOM_ROOT_PASSWORD=yes - networks: - - backend - restart: always - -networks: - backend: - driver: bridge diff --git a/tasks/dev.dockerfile b/tasks/dev.dockerfile deleted file mode 100644 index bc097f7..0000000 --- a/tasks/dev.dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -# Preload dependencies, -# only prepare the necessary runtime, and the subsequent listening and building work is completely handed over to cargo-make -FROM rust:latest - -RUN rustup target add wasm32-unknown-unknown -RUN cargo install cargo-make -RUN cargo install wasm-bindgen-cli@0.2.87 - -COPY ./Cargo.toml /home/Cargo.toml -COPY ./Makefile.toml /home/Makefile.toml - -VOLUME ["/home/target", "/home/packages"] - -ENV ROOT_DIR=/home/res -WORKDIR /home -ENTRYPOINT ["cargo", "make", "-p", "docker-inside", "dev-on-container-build"] -EXPOSE 80