Skip to content

Commit

Permalink
chore: fix dockerfile and github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
steveiliop56 committed Sep 3, 2024
1 parent b8f86be commit 2995712
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 47 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ jobs:
- name: Setup rust
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Set up node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Build
run: cargo build --verbose
run: ./build cargo-dev

build-image:
runs-on: ubuntu-latest
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ jobs:
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross

- name: Set up node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Build amd64 binary
run: |
cross build --target x86_64-unknown-linux-musl --release
./build cross x86_x64-unknown-linux-musl
mv target/x86_x64-unknown-linux-musl/release/cup ./cup-linux-amd64
- name: Build arm64 binary
run: |
cross build --target aarch64-unknown-linux-musl --release
./build cross aarch64-unknown-linux-musl
mv target/aarch64-unknown-linux-musl/release/cup ./cup-linux-arm64
- name: Upload binaries
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ jobs:
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross

- name: Set up node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Build amd64 binary
run: |
cross build --target x86_64-unknown-linux-musl --release
./build cross x86_x64-unknown-linux-musl
mv target/x86_x64-unknown-linux-musl/release/cup ./cup-linux-amd64
- name: Build arm64 binary
run: |
cross build --target aarch64-unknown-linux-musl --release
./build cross aarch64-unknown-linux-musl
mv target/aarch64-unknown-linux-musl/release/cup ./cup-linux-arm64
- name: Upload binaries
Expand Down
37 changes: 28 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
FROM rust:alpine AS build
WORKDIR /
# Build UI
FROM node:20-alpine3.20 as web

Check warning on line 2 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

# Copy web folder
COPY ./web ./web
WORKDIR web

Check warning on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-image

Relative workdir without an absolute workdir declared within the build can have unexpected results if the base image changes

WorkdirRelativePath: Relative workdir "web" can have unexpected results if the base image changes More info: https://docs.docker.com/go/dockerfile/rule/workdir-relative-path/

# Install requirements
RUN npm i

# Build
RUN npm run build

# Build Cup
FROM rust:1.80.1-alpine3.20 AS build

# Requirements
RUN apk add musl-dev

RUN USER=root cargo new --bin cup
# Copy rust
WORKDIR /cup

COPY Cargo.toml Cargo.lock .
RUN cargo build --release
RUN rm -rf src/
COPY Cargo.toml .
COPY Cargo.lock .
COPY ./src ./src

# Copy UI from web builder
COPY --from=web /web/dist src/static

COPY src src
# This is a very bad workaround, but cargo only triggers a rebuild this way for some reason
RUN printf "\n" >> src/main.rs
# Build
RUN cargo build --release

# Runner
FROM scratch

# Copy binary
COPY --from=build /cup/target/release/cup /cup

ENTRYPOINT ["/cup"]
33 changes: 29 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
#!/bin/sh
#!/bin/bash

rm -rf src/static
# Arguments
METHOD=$1
TARGET=$2

# Frontend
cd web/
bun run build

# Install requirements
npm i

# Build
npm run build

# Copy UI to src folder
cp -r dist/ ../src/static
cargo build $@

# Check selected method and build

if [[ $METHOD == 'cargo' ]]; then
echo "Building with cargo..."
cargo build --release
elif [[ $METHOD == 'cargo-dev' ]]; then
echo "Building with cargo using --verbose (dev)..."
elif [[ $METHOD == 'cross' ]]; then
echo "Building with cross for $TARGET..."
cross build --target $TARGET --release
else
echo "Unkown method!"
exit 1
fi
Binary file removed src/static/apple-touch-icon.png
Binary file not shown.
Binary file removed src/static/favicon.ico
Binary file not shown.
29 changes: 0 additions & 29 deletions src/static/favicon.svg

This file was deleted.

0 comments on commit 2995712

Please sign in to comment.