Skip to content

Commit

Permalink
ci: dockerfile with conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
Veirt committed Aug 5, 2024
1 parent 6496970 commit 7b36af7
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 79 deletions.
18 changes: 3 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,14 @@ jobs:
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Build and push x86_64
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.x86_64
file: Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build and push aarch64
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.aarch64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/arm64
platforms: linux/amd64,linux/arm64
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
47 changes: 47 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM --platform=$BUILDPLATFORM oven/bun:1-alpine AS css-builder
WORKDIR /temp
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile
COPY gridPlugin.js tailwind.config.js ./
COPY src ./src
RUN bunx tailwindcss -i ./src/style.css -o ./out.css --minify

FROM --platform=$BUILDPLATFORM rust:1.80 AS build

RUN apt-get update && apt-get install --no-install-recommends -y \
musl-tools \
&& rm -rf /var/lib/apt/lists/*

RUN rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl
RUN apt-get update && apt-get install --no-install-recommends -y \
gcc-aarch64-linux-gnu \
&& rm -rf /var/lib/apt/lists/*

# Set up the build environment
WORKDIR /usr/src
RUN USER=root cargo new --bin vesta
WORKDIR /usr/src/vesta
COPY Cargo.toml Cargo.lock ./
COPY src ./src

COPY docker/installer/linux .
RUN "./$TARGETPLATFORM.sh"

FROM scratch
WORKDIR /app
COPY ./static static
COPY --from=css-builder /temp/out.css ./static/style.css

ARG TARGETPLATFORM
ARG VESTA_ARCH
RUN case ${TARGETPLATFORM} in \
"linux/amd64") echo "x86_64-unknown-linux-musl" > /tmp/arch ;; \
"linux/arm64") echo "aarch64-unknown-linux-musl" > /tmp/arch ;; \
*) echo "unsupported" > /tmp/arch ;; \
esac && \
VESTA_ARCH=$(cat /tmp/arch) && \
rm /tmp/arch
COPY --from=build /usr/src/vesta/target/${VESTA_ARCH}}/release/vesta /app/vesta


CMD ["/app/vesta"]
36 changes: 0 additions & 36 deletions Dockerfile.aarch64

This file was deleted.

28 changes: 0 additions & 28 deletions Dockerfile.x86_64

This file was deleted.

7 changes: 7 additions & 0 deletions docker/installer/linux/arm64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh

set -eu

export CC_aarch64_unknown_linux_musl=aarch64-linux-gnu-gcc
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc
cargo build --release --target=aarch64-unknown-linux-musl
5 changes: 5 additions & 0 deletions docker/installer/linux/x86_64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh

set -eu

cargo build --release --target=x86_64-unknown-linux-musl

0 comments on commit 7b36af7

Please sign in to comment.