From ae217e789e3159edf0df9a4e5651002a9d4f546e Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 28 May 2023 01:25:57 +0100 Subject: [PATCH] Refined Dockerfile 12Mb --- .github/workflows/build-docker.yml | 40 ++++++++++++++++++++++++++++++ Dockerfile | 19 +++----------- 2 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/build-docker.yml diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 0000000..7e5d37b --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,40 @@ +name: Build + Publish Docker Image 🐳 + +on: + workflow_dispatch: + push: + branches: + - main + +env: + IMAGE_NAME: adguardian + DOCKER_USER: ${{ github.repository_owner }} + REGISTRY: ghcr.io + +jobs: + docker: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker images + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + platforms: linux/amd64,linux/arm64,linux/arm/v7 + tags: | + ${{ env.REGISTRY }}/${{ env.DOCKER_USER }}/${{ env.IMAGE_NAME }}:latest diff --git a/Dockerfile b/Dockerfile index 109a462..3020bfd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,13 @@ # syntax=docker/dockerfile:1.2 +# Build application - Copy assets, install deps and compile binary FROM --platform=$BUILDPLATFORM rust:1.69.0-alpine AS builder - -# Adding necessary packages -RUN apk update -RUN apk add pkgconfig openssl openssl-dev musl-dev - -# Set working directory in container; make directory if not exists -RUN mkdir -p /usr/src/adguardian +RUN apk add --no-cache pkgconfig openssl openssl-dev musl-dev WORKDIR /usr/src/adguardian - -# Copy all files from local computer to container -COPY Cargo.toml . -COPY Cargo.lock . -COPY src src - -# Build release application +COPY . . RUN cargo build --release - +# Run application - Using lightweight base, execute the binary FROM scratch COPY --from=builder /usr/src/adguardian/target/release/adguardian / ENTRYPOINT ["/adguardian"]