Skip to content

Commit

Permalink
ci: add docker publish
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Oct 28, 2024
1 parent 2f7badd commit f8570a2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 81 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
49 changes: 26 additions & 23 deletions .github/workflows/build_preconf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,37 @@ name: Build

on:
push:
branches: [ preconf ]

env:
CARGO_TERM_COLOR: always
branches:
- taiyi
pull_request:
types: [closed]
branches:
- taiyi

jobs:

build:
runs-on: self-hosted
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- uses: actions/checkout@v2
with:
fetch-depth: '0'
path: ./repos/${{ secrets.REPO_NAME }}
ref: ${{ github.ref }}
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Run Dockerfile
env:
DOCKER_REG_USR: ${{ secrets.DOCKER_REG_USR }}
DOCKER_REG_PW: ${{ secrets.DOCKER_REG_PW }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
REPO_NAME: ${{ secrets.REPO_NAME }}
run: |
DOCKER_BUILDKIT=1 docker build -t helix:preconf --build-arg AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID --build-arg AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY --build-arg REPO_NAME=$REPO_NAME -f ./repos/$REPO_NAME/Dockerfile .
DOCKER_BUILDKIT=1 docker tag helix:preconf $REGISTRY_URL/helix:preconf
DOCKER_BUILDKIT=1 docker login https://$REGISTRY_URL/ -u "$DOCKER_REG_USR" -p "$DOCKER_REG_PW"
DOCKER_BUILDKIT=1 docker push $REGISTRY_URL/helix:preconf
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/helix:latest
${{ secrets.DOCKER_USERNAME }}/helix:${{ github.sha }}
79 changes: 21 additions & 58 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,61 +1,24 @@
FROM rust:1.75.0 as helix

RUN apt update -y
RUN apt install -y clang
RUN apt install -y protobuf-compiler

RUN wget https://github.com/mozilla/sccache/releases/download/v0.3.1/sccache-v0.3.1-x86_64-unknown-linux-musl.tar.gz \
&& tar xzf sccache-v0.3.1-x86_64-unknown-linux-musl.tar.gz \
&& mv sccache-v0.3.1-x86_64-unknown-linux-musl/sccache /usr/local/bin/sccache \
&& chmod +x /usr/local/bin/sccache

ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
ARG REPO_NAME

RUN echo "REPO_NAME: $REPO_NAME"

# Test to make sure that aws access is set correctly
RUN test -n "$AWS_ACCESS_KEY_ID" || (echo "AWS_ACCESS_KEY_ID not set" && false)
RUN test -n "$AWS_SECRET_ACCESS_KEY" || (echo "AWS_SECRET_ACCESS_KEY not set" && false)

ENV SCCACHE_BUCKET=sccache-gtc
ENV SCCACHE_REGION=eu-west-1
ENV SCCACHE_S3_USE_SSL=true

# Copy necessary contents into the container at /app
ADD ./repos /app/

RUN ls -lah /app
RUN ls -lah /app/${REPO_NAME}

# Set the working directory to /app
WORKDIR /app/${REPO_NAME}

RUN --mount=type=cache,target=/root/.cargo \
--mount=type=cache,target=/usr/local/cargo/registry \
cargo fetch

# Run build
RUN --mount=type=cache,target=/root/.cargo \
--mount=type=cache,target=/usr/local/cargo/registry \
RUSTC_WRAPPER=/usr/local/bin/sccache cargo build -p helix-cmd --release

# Copy binary into the workdir
RUN mv /app/$REPO_NAME/target/release/helix-cmd /app/helix-cmd

# our final base
FROM debian:stable-slim

RUN mkdir /root/logs

RUN apt-get update
RUN apt-get install -y ca-certificates

FROM lukemathwalker/cargo-chef:latest-rust-1.81.0 AS chef
WORKDIR /app

COPY --from=helix /app/helix-cmd* ./
RUN apt update -y && apt install -y clang protobuf-compiler

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release

# We do not need the Rust toolchain to run the binary!
FROM debian:bookworm-slim AS runtime
RUN apt-get update && apt-get install -y libssl-dev
WORKDIR /app
COPY --from=builder /app/target/release/helix-cmd* ./

# set the startup command to run your binary
ENTRYPOINT ["/app/helix-cmd"]

ENTRYPOINT ["/app/helix-cmd"]

0 comments on commit f8570a2

Please sign in to comment.