Skip to content

Commit

Permalink
Merge pull request #123 from GiganticMinecraft/feature/cross
Browse files Browse the repository at this point in the history
feat: use cross to build
  • Loading branch information
Mitama authored Apr 12, 2023
2 parents b4593a6 + e8d6bd6 commit 7c880ef
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 139 deletions.
102 changes: 0 additions & 102 deletions .github/workflows/build-and-release-application.yaml

This file was deleted.

95 changes: 95 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Checking
on:
push:

env:
image_name: ghcr.io/giganticminecraft/seichi-poral-backend
RUST_BACKTRACE: full
SCCACHE_CACHE_SIZE: 2G
SCCACHE_VERSION: 0.3.3
# SCCACHE_RECACHE: 1 # Uncomment this to clear cache, then comment it back out

jobs:
rustfmt:
name: rustfmt check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rustfmt
override: true
- uses: LoliGothick/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
flags: --all
args: --config-path=./.cargo-husky/hooks/rustfmt.toml
working-directory: ./server

lint-and-test:
needs: [ rustfmt ]
name: Lint and test server
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

# reads toolchain info from /rust-toolchain.toml
# we are using a fork of actions-rs/toolchain for rust-toolchain.toml support
# (see https://github.com/actions-rs/toolchain/pull/209) for details.
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.68.2
target: x86_64-unknown-linux-musl
components: clippy, rustfmt

# buf CLIがビルドに必要
- uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Save sccache
id: restore-sccache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
/home/runner/.cache/sccache
~/.cargo/bin/sccache
key: sccache-${{ env.SCCACHE_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
sccache-${{ env.SCCACHE_VERSION }}-
- if: ${{ steps.restore-sccache.outputs.cache-hit == false }}
name: Install sccache
uses: actions-rs/cargo@v1
with:
command: install
args: --version=${{ env.SCCACHE_VERSION }} --force sccache

- name: Install Deps
run: sudo apt install -y musl-tools build-essential

- name: Start sccache server
run: sccache --start-server

- name: Cargo build
run: cargo build
working-directory: ./server

- uses: LoliGothick/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
deny: warnings
working-directory: ./server

- name: Cargo test
run: cargo test --all-features
working-directory: ./server

- name: Print sccache stats
run: sccache --show-stats
- name: Stop sccache server
run: sccache --stop-server || true
97 changes: 97 additions & 0 deletions .github/workflows/image-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Release docker images

on:
push:
branches:
- master

jobs:
build:
name: Build for ${{ matrix.docker-platform }}
strategy:
fail-fast: false
matrix:
include:
-
docker-platform: linux/amd64
cross-target: x86_64-unknown-linux-gnu
-
docker-platform: linux/arm64/v8
cross-target: aarch64-unknown-linux-gnu
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@master
-
name: Setup rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.68.2
target: ${{ matrix.cross-target }}
override: true
-
name: Build binary using cross
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --manifest-path server/Cargo.toml --target ${{ matrix.cross-target }} --release
-
name: Upload artifact to collect in next job
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.cross-target }}
path: server/target/${{ matrix.cross-target }}/release/entrypoint

release-all:
name: Push docker image for all platforms
runs-on: ubuntu-latest
needs: build
env:
image_name: seichi-portal-backend
steps:
-
name: Checkout
uses: actions/checkout@master
-
uses: actions/download-artifact@v3
with:
name: x86_64-unknown-linux-gnu
path: docker/artifacts/x86_64-unknown-linux-gnu
-
uses: actions/download-artifact@v3
with:
name: aarch64-unknown-linux-gnu
path: docker/artifacts/aarch64-unknown-linux-gnu
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
id: prepare_image_id
name: Prepare image id's components
run: |
image_id=ghcr.io/${{ github.repository_owner }}/${{ env.image_name }}
echo "lowercase_id=$(echo $image_id | tr '[A-Z]' '[a-z]')" >> $GITHUB_OUTPUT
echo "short-ref=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT
echo "branch=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_OUTPUT
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: docker
platforms: linux/amd64,linux/arm64/v8
push: true
tags: |
${{ steps.prepare_image_id.outputs.lowercase_id }}:latest
${{ steps.prepare_image_id.outputs.lowercase_id }}:${{ steps.prepare_image_id.outputs.branch }}-${{ steps.prepare_image_id.outputs.short-ref }}
36 changes: 0 additions & 36 deletions Dockerfile

This file was deleted.

19 changes: 19 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# syntax=docker/dockerfile:1.4
FROM debian:latest as shell

COPY --link / /work/

RUN case "$(uname -m)" in \
"x86_64" ) cp /work/artifacts/x86_64-unknown-linux-gnu/entrypoint /seichi-portal-backend ;; \
"armv7l" ) cp /work/artifacts/armv7-unknown-linux-gnueabihf/entrypoint /seichi-portal-backend ;; \
"aarch64" ) cp /work/artifacts/aarch64-unknown-linux-gnu/entrypoint /seichi-portal-backend ;; \
* ) exit 1 \
;; \
esac

FROM gcr.io/distroless/cc
LABEL org.opencontainers.image.source=https://github.com/GiganticMinecraft/seichi-portal-backend

COPY --from=shell --link /seichi-portal-backend /usr/local/bin/seichi-portal-backend

ENTRYPOINT ["/usr/local/bin/seichi-portal-backend"]
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.68.0"
channel = "1.68.2"
components = [ "rustfmt", "clippy", "cargo" ]
profile = "minimal"

0 comments on commit 7c880ef

Please sign in to comment.