mirror of
https://github.com/SinTan1729/chhoto-url
synced 2024-10-16 21:33:54 -05:00
Merge 629e66a57c
into d6dcd2f18d
This commit is contained in:
commit
21bde86a30
6 changed files with 52 additions and 33 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
||||||
# Ignore cargo build outputs
|
# Ignore build outputs
|
||||||
actix/target
|
actix/target
|
||||||
|
.docker
|
||||||
|
|
||||||
# Ignore SQLite file
|
# Ignore SQLite file
|
||||||
urls.sqlite
|
urls.sqlite
|
||||||
|
|
10
Dockerfile
10
Dockerfile
|
@ -7,20 +7,20 @@ COPY ./actix/src ./src
|
||||||
RUN cargo chef prepare --recipe-path recipe.json
|
RUN cargo chef prepare --recipe-path recipe.json
|
||||||
|
|
||||||
FROM chef as builder
|
FROM chef as builder
|
||||||
|
ARG target=x86_64-unknown-linux-musl
|
||||||
RUN apt-get update && apt-get install -y musl-tools
|
RUN apt-get update && apt-get install -y musl-tools
|
||||||
RUN rustup target add x86_64-unknown-linux-musl
|
RUN rustup target add $target
|
||||||
|
|
||||||
COPY --from=planner /chhoto-url/recipe.json recipe.json
|
COPY --from=planner /chhoto-url/recipe.json recipe.json
|
||||||
# Build dependencies - this is the caching Docker layer
|
# Build dependencies - this is the caching Docker layer
|
||||||
RUN cargo chef cook --release --target=x86_64-unknown-linux-musl --recipe-path recipe.json
|
RUN cargo chef cook --release --target=$target --recipe-path recipe.json
|
||||||
|
|
||||||
COPY ./actix/Cargo.toml ./actix/Cargo.lock .
|
COPY ./actix/Cargo.toml ./actix/Cargo.lock .
|
||||||
COPY ./actix/src ./src
|
COPY ./actix/src ./src
|
||||||
# Build application
|
# Build application
|
||||||
RUN cargo build --release --target=x86_64-unknown-linux-musl --locked --bin chhoto-url
|
RUN cargo build --release --target=$target --locked --bin chhoto-url
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
COPY --from=builder /chhoto-url/target/x86_64-unknown-linux-musl/release/chhoto-url /chhoto-url
|
COPY --from=builder /chhoto-url/target/$target/release/chhoto-url /chhoto-url
|
||||||
COPY ./resources /resources
|
COPY ./resources /resources
|
||||||
ENTRYPOINT ["/chhoto-url"]
|
ENTRYPOINT ["/chhoto-url"]
|
||||||
|
|
||||||
|
|
15
Dockerfile.multiarch
Normal file
15
Dockerfile.multiarch
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
FROM scratch as builder-amd64
|
||||||
|
COPY ./actix/target/x86_64-unknown-linux-musl/release/chhoto-url /chhoto-url
|
||||||
|
|
||||||
|
FROM scratch as builder-arm64
|
||||||
|
COPY ./actix/target/aarch64-unknown-linux-musl/release/chhoto-url /chhoto-url
|
||||||
|
|
||||||
|
FROM scratch as builder-arm
|
||||||
|
COPY ./actix/target/armv7-unknown-linux-musleabihf/release/chhoto-url /chhoto-url
|
||||||
|
|
||||||
|
ARG TARGETARCH
|
||||||
|
FROM builder-$TARGETARCH
|
||||||
|
COPY ./resources /resources
|
||||||
|
|
||||||
|
ENTRYPOINT ["/chhoto-url"]
|
||||||
|
|
19
Makefile
Normal file
19
Makefile
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
USERNAME := ${DOCKER_USERNAME}
|
||||||
|
|
||||||
|
setup:
|
||||||
|
cargo install cross
|
||||||
|
docker buildx create --use --platform=linux/arm64,linux/amd64 --name multi-platform-builder
|
||||||
|
docker buildx inspect --bootstrap
|
||||||
|
|
||||||
|
build:
|
||||||
|
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 .
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo clean --manifest-path=actix/Cargo.toml
|
||||||
|
|
||||||
|
.PHONY: build
|
10
README.md
10
README.md
|
@ -75,10 +75,16 @@ place, resulting in possibly unwanted behavior.
|
||||||
|
|
||||||
## Building and running with docker
|
## Building and running with docker
|
||||||
### `docker run` method
|
### `docker run` method
|
||||||
0. (Only if you really want to) Build the image
|
0. (Only if you really want to) Build the image for the default `x86_64-unknown-linux-musl` target:
|
||||||
```
|
```
|
||||||
docker build . -t chhoto-url:latest
|
docker build . -t chhoto-url
|
||||||
```
|
```
|
||||||
|
For building on `arm64` or `arm/v7`, use the following:
|
||||||
|
```
|
||||||
|
docker build . -t chhoto-url --build-arg target=<desired-target>
|
||||||
|
```
|
||||||
|
For cross-compilation, take a look at the `Makefile`. It builds and pushes for `linux/amd64`, `linux/aarch64`
|
||||||
|
and `linux/arm/v7` architectures. For any other architectures, open a discussion, and I'll try to help you out.
|
||||||
1. Run the image
|
1. Run the image
|
||||||
```
|
```
|
||||||
docker run -p 4567:4567
|
docker run -p 4567:4567
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
#!/bin/env bash
|
#!/bin/env bash
|
||||||
|
|
||||||
if [ "$1" == "dev" ]; then
|
if [ "$1" == "dev" ]; then
|
||||||
name="chhoto-url"
|
docker buildx build --push --tag sintan1729/$name:dev .
|
||||||
docker build -t $name .
|
|
||||||
docker tag $name sintan1729/$name:dev
|
|
||||||
docker push sintan1729/$name:dev
|
|
||||||
|
|
||||||
elif [ "$1" == "release" ]; then
|
elif [ "$1" == "release" ]; then
|
||||||
v_patch=$(cat actix/Cargo.toml | sed -rn 's/^version = "(.+)"$/\1/p')
|
v_patch=$(cat actix/Cargo.toml | sed -rn 's/^version = "(.+)"$/\1/p')
|
||||||
|
@ -12,26 +9,7 @@ elif [ "$1" == "release" ]; then
|
||||||
v_major=$(echo $v_minor | sed -rn 's/^(.+)\..+$/\1/p')
|
v_major=$(echo $v_minor | sed -rn 's/^(.+)\..+$/\1/p')
|
||||||
|
|
||||||
name="chhoto-url"
|
name="chhoto-url"
|
||||||
|
docker buildx build --push --tag sintan1729/$name:$v_major --tag sintan1729/$v_minor: \
|
||||||
docker build -t $name .
|
--tag sintan1729/$name:$v_patch --tag sintan1729/$name:latest --platform linux/amd64,linux/arm64
|
||||||
|
|
||||||
for tag in $v_major $v_minor $v_patch latest
|
|
||||||
do
|
|
||||||
docker tag $name sintan1729/$name:$tag
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Do you want to push these to Docker Hub?"
|
|
||||||
select yn in "Yes" "No";
|
|
||||||
do
|
|
||||||
if [ "$yn"="Yes" ]; then
|
|
||||||
for tag in $v_major $v_minor $v_patch latest
|
|
||||||
do
|
|
||||||
docker push sintan1729/$name:$tag
|
|
||||||
done
|
|
||||||
else
|
|
||||||
echo "Okay! Not pushing."
|
|
||||||
fi
|
|
||||||
break
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue