Skip to content

Commit

Permalink
add multiplatform build for anki (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyTurtleDev authored Jan 22, 2024
1 parent c6f2961 commit 92a91f1
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
echo 'version=${{ matrix.version }}'
echo 'path=${{ matrix.path }}'
echo 'name=${{ matrix.name }}'
echo 'test=${{ matrix.test }}'
echo 'platforms=${{ matrix.platforms }}'
echo 'docker_tags=${{ matrix.docker_tags }}'
echo 'index=${{ matrix.index }}'
Expand Down Expand Up @@ -70,7 +71,7 @@ jobs:
uses: docker/build-push-action@v3
with:
context: ${{ matrix.path }}
push: ${{ github.ref == 'refs/heads/main' }}
push: ${{ github.ref == 'refs/heads/main' || matrix.test }}
build-args: version=${{ matrix.version }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Click on the software name at the table below, to go to the readme of the associ

| Software | multiplatform | auto version update | version tags | semver tags |
|:-----------------------------------------------|:-------------:|:-------------------:|:------------:|:-----------:|
| [Anki Sync Server](dockerfiles/anki/README.md) | ||||
| [Anki Sync Server](dockerfiles/anki/README.md) | ||||
| Repetier-Server |||||
| yt-dlp |||||
27 changes: 19 additions & 8 deletions dockerfiles/anki/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
FROM rust AS builder
FROM --platform=$BUILDPLATFORM rust AS builder
SHELL ["/bin/bash", "-uo", "pipefail", "-c"]

ARG version
ARG TARGETPLATFORM

ENV TARGET x86_64-unknown-linux-musl
RUN rustup target add "$TARGET"
# add the rust target for the target architecture
RUN if [ "$TARGETPLATFORM" == "linux/amd64" ]; then echo "x86_64-unknown-linux-musl" >/.target; \
elif [ "$TARGETPLATFORM" == "linux/arm64" ]; then echo "aarch64-unknown-linux-musl" >/.target; \
elif [ "$TARGETPLATFORM" == "linux/arm/v7" ]; then echo "armv7-unknown-linux-musleabihf" >/.target; \
else echo "Unknown architecture $TARGETPLATFORM"; exit 1; \
fi
RUN rustup target add "$(cat /.target)"

RUN apt-get -y update && apt-get -y install protobuf-compiler musl musl-dev musl-tools
COPY cargo-config.toml $CARGO_HOME/config.toml
RUN echo "$CARGO_HOME/config.toml"
RUN dpkg --add-architecture arm64
RUN dpkg --add-architecture armhf
# armv7 => armhf
RUN apt-get -y update && apt-get -y install protobuf-compiler clang mold musl musl-dev musl-dev:arm64 musl-dev:armhf musl-tools
ENV PROTOC=/usr/bin/protoc
RUN echo "build version ${version}"
RUN cargo install --locked --target "$TARGET" --git https://github.com/ankitects/anki.git --tag ${version} anki-sync-server
RUN ldd /usr/local/cargo/bin/anki-sync-server
RUN echo "build anki version ${version} for $(cat /.target)"
RUN cargo install --locked --target "$(cat /.target)" --git https://github.com/ankitects/anki.git --tag ${version} anki-sync-server
#RUN ldd /usr/local/cargo/bin/anki-sync-server


FROM scratch
FROM --platform=$BUILDPLATFORM scratch
ENV SYNC_BASE=/data
COPY --from=builder --chmod=0755 /usr/local/cargo/bin/anki-sync-server /
CMD ["./anki-sync-server"]
2 changes: 1 addition & 1 deletion dockerfiles/anki/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The official selfhosted sync sever for the [anki](https://github.com/ankitects/a
Do not confuse this official server, with the old unofficial (unmaintained?) [community sync server](https://github.com/ankicommunity/anki-sync-server).

* url: [`ghcr.io/luckyturtledev/anki`](https://ghcr.io/luckyturtledev/anki)
* multiplatform:
* multiplatform:
* semver tags: ❌
* version tags: ✅
* auto update: ✅
Expand Down
20 changes: 20 additions & 0 deletions dockerfiles/anki/cargo-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[env]
CC_armv7-unknown-linux-musleabihf = "clang -I /usr/include/arm-linux-musleabihf -target armv7-unknown-linux-musleabihf -fuse-ld=mold"
CXX_armv7-unknown-linux-musleabihf = "clang++ -I /usr/include/arm-linux-musleabihf -target armv7-unknown-linux-musleabihf -fuse-ld=mold"
CC_aarch64-unknown-linux-musl = "clang -I /usr/include/aarch64-linux-musl -target aarch64-unknown-linux-musl -fuse-ld=mold"
CXX_aarch64-unknown-linux-musl = "clang++ -I /usr/include/aarch64-linux-musl -target aarch64-unknown-linux-musl -fuse-ld=mold"
CC_x86_64-unknown-linux-musl = "clang -I /usr/include/x86_64-linux-musl -target x86_64-unknown-linux-musl -fuse-ld=mold"
CXX_x86_64-unknown-linux-musl = "clang++ -I /usr/include/x86_64-linux-musl -target x86_64-unknown-linux-musl -fuse-ld=mold"


[target.x86_64-unknown-linux-musl]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]

[target.aarch64-unknown-linux-musl]
linker = "clang"
rustflags = ["-C", "link-arg=--target=aarch64-unknown-linux-musl", "-C", "link-arg=-fuse-ld=mold"]

[target.armv7-unknown-linux-musleabihf]
linker = "clang"
rustflags = ["-C", "link-arg=--target=armv7-unknown-linux-musleabihf", "-C", "link-arg=-fuse-ld=mold"]
7 changes: 7 additions & 0 deletions dockerfiles/anki/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ repo = "ankitects/anki"

[tags]
version = true

[config]
platforms = [
"linux/amd64",
"linux/arm/v7",
"linux/arm64/v8",
]
14 changes: 11 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ impl Default for TagConfig {
#[derive(Debug, Deserialize)]
#[serde(default, deny_unknown_fields)]
struct ConfigConfig {
platforms: Vec<String>
platforms: Vec<String>,
test: bool
}

impl Default for ConfigConfig {
fn default() -> Self {
Self {
platforms: vec!["linux/amd64".to_owned()]
platforms: vec!["linux/amd64".to_owned()],
test: false
}
}
}
Expand All @@ -66,6 +68,7 @@ struct Output {
version: String,
path: String,
name: String,
test: bool,
platforms: String,
docker_tags: String,
index: String
Expand Down Expand Up @@ -168,10 +171,15 @@ fn process_dir(dir: &Path) -> anyhow::Result<Option<Output>> {
platforms += ",";
}
platforms.pop();
let mut name = String::from(dir_name);
if config.config.test {
name = format!("test-{name}");
}
return Ok(Some(Output {
version,
path,
name: dir_name.into(),
name,
test: config.config.test,
platforms,
docker_tags,
index: new_index_str
Expand Down

0 comments on commit 92a91f1

Please sign in to comment.