-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a local script for pushing Docker images
- Loading branch information
1 parent
d37eb3a
commit 89c5298
Showing
3 changed files
with
58 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
FROM rust:alpine AS builder | ||
# This file is not intended to be used directly ; | ||
# please refer to the build script instead | ||
|
||
RUN apk add musl-dev perl make | ||
FROM debian:bullseye-slim | ||
|
||
WORKDIR /app | ||
|
||
COPY Cargo.toml Cargo.lock . | ||
COPY src src | ||
RUN cargo build --release | ||
|
||
FROM alpine | ||
# These two are provided by docker buildx | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
ARG TARGETVARIANT | ||
|
||
WORKDIR /app | ||
COPY --from=builder /app/target/release/tapo-rest . | ||
COPY target/building-for-docker/artifacts/${TARGETOS}/${TARGETARCH}/${TARGETVARIANT}/tapo-rest ./ | ||
|
||
ENTRYPOINT ["./tapo-rest", "/app/devices.json", "--port=80"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Due to difficulties building cross-platform binaries with Docker, | ||
# I resort here to building locally using `cross` and then copying the | ||
# output into a container. | ||
|
||
# Ensure 'cross' is installed | ||
if whereis('cross') == null { | ||
throw 'Please install "cross" to continue.' | ||
} | ||
|
||
# Ensure a container engine is installed | ||
if whereis('docker') == null && whereis('podman') == null { | ||
throw 'Please install either "docker" or "podman" to continue.' | ||
} | ||
|
||
# Get name and version from the manifest | ||
let manifest = parseToml(readFile('Cargo.toml')) | ||
let { name, version } = $manifest['package'] | ||
|
||
# List build targets | ||
let targets = map([ | ||
['aarch64-unknown-linux-musl', 'linux/arm64'], | ||
['x86_64-unknown-linux-musl' , 'linux/amd64'] | ||
]) | ||
|
||
# Build for every image | ||
let buildDir = 'target/building-for-docker' | ||
|
||
for target, dockerPlatform in $targets { | ||
echo "\nBuilding for target: $target...\n" | ||
|
||
# We use a different target directory for each crate and each target, otherwise dependencies build | ||
# may clash between platforms | ||
let targetDir = "$buildDir/targets/$target" | ||
mkdir -p -i $targetDir | ||
cross build --release --target $target --target-dir $targetDir | ||
|
||
# Put build artifact in the correct directory | ||
let artifactsFile = "$buildDir/artifacts/$dockerPlatform/$name" | ||
mkdir -p (parentDir($artifactsFile)) | ||
cp "$targetDir/$target/release/$name" $artifactsFile | ||
} | ||
|
||
# Build and publish Docker images | ||
echo '\nPublishing on Docker Hub...\n' | ||
|
||
docker buildx build --push . \ | ||
--platform ($targets.values().join(',')) \ | ||
--tag "clementnerma/$name:$version" \ | ||
--tag "clementnerma/$name:latest" |