From 0eda147fa571e901f16d20d98c289e31f9699e9f Mon Sep 17 00:00:00 2001 From: steamroller-airmash <38710707+steamroller-airmash@users.noreply.github.com> Date: Fri, 25 Feb 2022 20:09:08 -0500 Subject: [PATCH] Add a workflow to deploy docker containers (#138) --- .cargo/config.toml | 6 ++++ .github/workflows/build-images.yml | 35 +++++++++++++++++++ CTF.dockerfile | 49 --------------------------- Dockerfile | 54 ++++++++---------------------- FFA.dockerfile | 49 --------------------------- 5 files changed, 55 insertions(+), 138 deletions(-) create mode 100644 .cargo/config.toml create mode 100644 .github/workflows/build-images.yml delete mode 100644 CTF.dockerfile delete mode 100644 FFA.dockerfile diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..c0ecb9ff --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,6 @@ + +[profile.prod] +inherits = "release" +debug = true +lto = "thin" +codegen-units = 1 diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml new file mode 100644 index 00000000..348d694b --- /dev/null +++ b/.github/workflows/build-images.yml @@ -0,0 +1,35 @@ + +on: + workflow_dispatch: + inputs: + is_release: + default: 'true' + type: boolean + push: + +name: docker + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + target: [ctf, ffa, base] + steps: + - uses: actions/checkout@v2 + - uses: docker/setup-buildx-action@v1 + + - uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/build-push-action@v2 + with: + context: . + tags: ghcr.io/steamroller-airmash/server:${{ matrix.target }} + build-args: | + TARGET=${{ matrix.target }} + push: ${{ github.event.is_release == 'true' }} + diff --git a/CTF.dockerfile b/CTF.dockerfile deleted file mode 100644 index ec1bd8e0..00000000 --- a/CTF.dockerfile +++ /dev/null @@ -1,49 +0,0 @@ -FROM clux/muslrust:nightly - -WORKDIR /build - -RUN USER=root cargo new --bin base -COPY ./base/Cargo.toml ./base/Cargo.toml - -RUN USER=root cargo new --bin bounded-queue -COPY ./bounded-queue/Cargo.toml ./bounded-queue/Cargo.toml - -RUN USER=root cargo new --bin ctf -COPY ./ctf/Cargo.toml ./ctf/Cargo.toml - -RUN USER=root cargo new --bin ffa -COPY ./ffa/Cargo.toml ./ffa/Cargo.toml - -RUN USER=root cargo new --bin server -COPY ./server/Cargo.toml ./server/Cargo.toml - -RUN USER=root cargo new --bin special-map -COPY ./special-map/Cargo.toml ./special-map/Cargo.toml - -COPY ./Cargo.lock ./Cargo.lock -COPY ./Cargo.toml ./Cargo.toml - -RUN cargo build --release - -RUN rm ./base/src/*.rs -RUN rm ./bounded-queue/src/*.rs -RUN rm ./ctf/src/*.rs -RUN rm ./ffa/src/*.rs -RUN rm ./server/src/*.rs -RUN rm ./special-map/src/*.rs - -COPY . /build - -RUN cargo build --release -RUN mkdir /artifacts -RUN mv target/x86_64-unknown-linux-musl/release/airmash-server-ctf /artifacts/airmash-server - -FROM alpine:latest - -EXPOSE 3501 - -ENV RUST_LOG=info,ws=warn - -COPY --from=0 /artifacts/airmash-server /app/airmash-server - -ENTRYPOINT [ "/app/airmash-server" ] diff --git a/Dockerfile b/Dockerfile index c4fbda23..966c99d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,49 +1,23 @@ -FROM clux/muslrust:nightly +FROM rust:1.59-slim-bullseye as build-env -WORKDIR /build - -RUN USER=root cargo new --bin base -COPY ./base/Cargo.toml ./base/Cargo.toml - -RUN USER=root cargo new --bin bounded-queue -COPY ./bounded-queue/Cargo.toml ./bounded-queue/Cargo.toml - -RUN USER=root cargo new --bin ctf -COPY ./ctf/Cargo.toml ./ctf/Cargo.toml - -RUN USER=root cargo new --bin ffa -COPY ./ffa/Cargo.toml ./ffa/Cargo.toml - -RUN USER=root cargo new --bin server -COPY ./server/Cargo.toml ./server/Cargo.toml - -RUN USER=root cargo new --bin special-map -COPY ./special-map/Cargo.toml ./special-map/Cargo.toml - -COPY ./Cargo.lock ./Cargo.lock -COPY ./Cargo.toml ./Cargo.toml - -RUN cargo build --release - -RUN rm ./base/src/*.rs -RUN rm ./bounded-queue/src/*.rs -RUN rm ./ctf/src/*.rs -RUN rm ./ffa/src/*.rs -RUN rm ./server/src/*.rs -RUN rm ./special-map/src/*.rs +RUN apt-get update \ + && apt-get install -y dwz \ + && apt-get clean +WORKDIR /build COPY . /build -RUN cargo build --release -RUN mkdir /artifacts -RUN mv target/x86_64-unknown-linux-musl/release/airmash-server-base /artifacts/airmash-server +ARG TARGET -FROM alpine:latest +RUN cargo build --profile prod --bin airmash-server-${TARGET} +RUN mv target/prod/airmash-server-${TARGET} target/airmash-server +RUN dwz -L none -l none --odr target/airmash-server -EXPOSE 3501 +FROM debian:bullseye-slim -COPY --from=0 /artifacts/airmash-server /app/airmash-server +COPY --from=build-env /build/target/airmash-server / -ENV RUST_LOG=info,ws=warn +EXPOSE 3501/tcp +ENV RUST_LOG=info -ENTRYPOINT [ "/app/airmash-server" ] +ENTRYPOINT [ "/airmash-server" ] diff --git a/FFA.dockerfile b/FFA.dockerfile deleted file mode 100644 index 264f8844..00000000 --- a/FFA.dockerfile +++ /dev/null @@ -1,49 +0,0 @@ -FROM clux/muslrust:nightly - -WORKDIR /build - -RUN USER=root cargo new --bin base -COPY ./base/Cargo.toml ./base/Cargo.toml - -RUN USER=root cargo new --bin bounded-queue -COPY ./bounded-queue/Cargo.toml ./bounded-queue/Cargo.toml - -RUN USER=root cargo new --bin ctf -COPY ./ctf/Cargo.toml ./ctf/Cargo.toml - -RUN USER=root cargo new --bin ffa -COPY ./ffa/Cargo.toml ./ffa/Cargo.toml - -RUN USER=root cargo new --bin server -COPY ./server/Cargo.toml ./server/Cargo.toml - -RUN USER=root cargo new --bin special-map -COPY ./special-map/Cargo.toml ./special-map/Cargo.toml - -COPY ./Cargo.lock ./Cargo.lock -COPY ./Cargo.toml ./Cargo.toml - -RUN cargo build --release - -RUN rm ./base/src/*.rs -RUN rm ./bounded-queue/src/*.rs -RUN rm ./ctf/src/*.rs -RUN rm ./ffa/src/*.rs -RUN rm ./server/src/*.rs -RUN rm ./special-map/src/*.rs - -COPY . /build - -RUN cargo build --release -RUN mkdir /artifacts -RUN mv target/x86_64-unknown-linux-musl/release/airmash-server-ffa /artifacts/airmash-server - -FROM alpine:latest - -EXPOSE 3501 - -COPY --from=0 /artifacts/airmash-server /app/airmash-server - -ENV RUST_LOG=info,ws=warn - -ENTRYPOINT [ "/app/airmash-server" ]