Browse Source

Changes to ci

instead of docker layer caching, build binary in runner itself and copy
binary to dockerfile
old Dockerfile is now build.Dockerfile whereas new one is ci.Dockerfile
caching docker layers was taking more time than building the image from
 scratch
 add powerpc build (for the 100th time) but without cross in it's own
 job
devel
Rohan Sircar 1 year ago
parent
commit
565e6bc5e4
  1. 90
      .github/workflows/ci.yml
  2. 0
      build.Dockerfile
  3. 0
      build.Dockerfile.dockerignore
  4. 27
      ci.Dockerfile
  5. 3
      ci.Dockerfile.dockerignore

90
.github/workflows/ci.yml

@ -1,8 +1,4 @@
# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md
#
# While our "example" application has the platform-specific code,
# for simplicity we are compiling and testing everything on the Ubuntu environment only.
# For multi-OS testing see the `cross.yml` workflow.
on: [push, pull_request]
@ -15,18 +11,15 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@v1.2.0
- name: Run cargo check
- name: Run Cargo Check
uses: actions-rs/cargo@v1
with:
command: check
@ -37,7 +30,6 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
@ -47,7 +39,7 @@ jobs:
- name: Rust Cache
uses: Swatinem/rust-cache@v1.2.0
- name: Run cargo test
- name: Run Tests
uses: actions-rs/cargo@v1
with:
command: test
@ -58,7 +50,6 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
@ -68,31 +59,23 @@ jobs:
components: rustfmt, clippy
- name: Rust Cache
uses: Swatinem/rust-cache@v1.2.0
- name: Run cargo fmt
- name: Run Cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Run cargo clippy
- name: Run Cargo clippy
uses: actions-rs/cargo@v1
# continue-on-error: true
with:
command: clippy
args: -- -D warnings
build:
name: Build Binaries
build-aarch64:
name: Build aarch64 Binaries
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-latest
needs: [check, test, lints]
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
# - powerpc64-unknown-linux-gnu
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
@ -105,20 +88,47 @@ jobs:
path: |
~/.cargo/registry
~/.cargo/git
~/.cargo/bin
~/.cargo/.crates2.json
~/.cargo/.crates.toml
target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
# - name: Rust Cache
# uses: Swatinem/rust-cache@v1.2.0
# - name: Install PowerPC GCC
# if: matrix.target == 'powerpc64-unknown-linux-gnu'
# run: |
# sudo apt-get install -y gcc-powerpc-linux-gnu
key: ${{ runner.os }}-aarch64-unknown-linux-gnu-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Compile
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --release --target=${{ matrix.target }}
args: --release --target=aarch64-unknown-linux-gnu
build-ppc:
name: Build PowerPC Binaries
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
continue-on-error: true
runs-on: ubuntu-latest
needs: [check, test, lints]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
override: true
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.cargo/bin
~/.cargo/.crates2.json
~/.cargo/.crates.toml
target
key: ${{ runner.os }}-powerpc64-unknown-linux-gnu-cargo-${{ hashFiles('**/Cargo.lock') }}
run: sudo apt-get install -y gcc-powerpc-linux-gnu
- name: Compile
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target=powerpc64-unknown-linux-gnu
publish-docker:
name: Build and Publish Docker Image
@ -127,15 +137,25 @@ jobs:
needs: [check, test, lints]
steps:
- uses: actions/checkout@v2
- name: Docker layer cache
uses: satackey/action-docker-layer-caching@v0.0.11
continue-on-error: true
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: x86_64-unknown-linux-gnu
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@v1.2.0
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: rohansircar
password: ${{ secrets.DOCKER_LOGIN_PASSWORD }}
- name: Compile
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Build Image
run: docker build -t rohansircar/actix-demo:latest .
run: docker build -f ci.Dockerfile -t rohansircar/actix-demo:latest .
env: DOCKER_BUILDKIT=1
- name: Publish Image
run: docker push rohansircar/actix-demo:latest

0
Dockerfile → build.Dockerfile

0
.dockerignore → build.Dockerfile.dockerignore

27
ci.Dockerfile

@ -0,0 +1,27 @@
FROM debian:buster-slim
ARG APP=/usr/src/app
RUN apt-get update \
&& apt-get install -y ca-certificates tzdata \
&& rm -rf /var/lib/apt/lists/*
EXPOSE 8000
ENV TZ=Etc/UTC \
APP_USER=appuser
RUN groupadd $APP_USER \
&& useradd -g $APP_USER $APP_USER \
&& mkdir -p ${APP}
COPY ./.env ${APP}/.env
COPY ./migrations ${APP}/migrations
COPY ./static ${APP}/static
COPY ./db/empty.db ${APP}/app.db
COPY ./target/release/actix-demo ${APP}/actix-demo
RUN chown -R $APP_USER:$APP_USER ${APP}
USER $APP_USER
WORKDIR ${APP}
CMD ["./actix-demo"]

3
ci.Dockerfile.dockerignore

@ -0,0 +1,3 @@
.git
.idea
.vscode
Loading…
Cancel
Save