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 3 years 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 # 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:
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')) 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') }}
# - 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 - 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: 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 - 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

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