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
This commit is contained in:
Rohan Sircar 2021-04-24 22:46:11 +05:30
parent 7b18bd8967
commit 565e6bc5e4
5 changed files with 85 additions and 35 deletions

View File

@ -1,8 +1,4 @@
# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md # 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] on: [push, pull_request]
@ -15,18 +11,15 @@ jobs:
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Install stable toolchain - name: Install stable toolchain
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
toolchain: stable toolchain: stable
override: true override: true
- name: Rust Cache - name: Rust Cache
uses: Swatinem/rust-cache@v1.2.0 uses: Swatinem/rust-cache@v1.2.0
- name: Run Cargo Check
- name: Run cargo check
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: check command: check
@ -37,7 +30,6 @@ jobs:
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Install stable toolchain - name: Install stable toolchain
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
@ -47,7 +39,7 @@ jobs:
- name: Rust Cache - name: Rust Cache
uses: Swatinem/rust-cache@v1.2.0 uses: Swatinem/rust-cache@v1.2.0
- name: Run cargo test - name: Run Tests
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: test command: test
@ -58,7 +50,6 @@ jobs:
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Install stable toolchain - name: Install stable toolchain
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
@ -68,31 +59,23 @@ jobs:
components: rustfmt, clippy components: rustfmt, clippy
- name: Rust Cache - name: Rust Cache
uses: Swatinem/rust-cache@v1.2.0 uses: Swatinem/rust-cache@v1.2.0
- name: Run Cargo fmt
- name: Run cargo fmt
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: fmt command: fmt
args: --all -- --check args: --all -- --check
- name: Run Cargo clippy
- name: Run cargo clippy
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
# continue-on-error: true # continue-on-error: true
with: with:
command: clippy command: clippy
args: -- -D warnings args: -- -D warnings
build: build-aarch64:
name: Build Binaries name: Build aarch64 Binaries
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [check, test, lints] needs: [check, test, lints]
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
# - powerpc64-unknown-linux-gnu
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
@ -105,20 +88,47 @@ jobs:
path: | path: |
~/.cargo/registry ~/.cargo/registry
~/.cargo/git ~/.cargo/git
~/.cargo/bin
~/.cargo/.crates2.json
~/.cargo/.crates.toml
target target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} key: ${{ runner.os }}-aarch64-unknown-linux-gnu-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
- name: Compile - name: Compile
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
use-cross: true use-cross: true
command: build 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: publish-docker:
name: Build and Publish Docker Image name: Build and Publish Docker Image
@ -127,15 +137,25 @@ jobs:
needs: [check, test, lints] needs: [check, test, lints]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Docker layer cache - uses: actions-rs/toolchain@v1
uses: satackey/action-docker-layer-caching@v0.0.11 with:
continue-on-error: true 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 - name: Login to Docker Hub
uses: docker/login-action@v1 uses: docker/login-action@v1
with: with:
username: rohansircar username: rohansircar
password: ${{ secrets.DOCKER_LOGIN_PASSWORD }} password: ${{ secrets.DOCKER_LOGIN_PASSWORD }}
- name: Compile
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Build Image - 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 - name: Publish Image
run: docker push rohansircar/actix-demo:latest run: docker push rohansircar/actix-demo:latest

27
ci.Dockerfile Normal file
View File

@ -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"]

View File

@ -0,0 +1,3 @@
.git
.idea
.vscode