From 98a062dbd991cbe50371255067c62867a6aef129 Mon Sep 17 00:00:00 2001 From: Dimitri Date: Fri, 20 Sep 2024 14:03:17 +0700 Subject: [PATCH] Add github actions to build docker image --- .github/workflows/build-img.yml | 50 +++++++++++++++++++++++++ Full.Dockerfile | 66 +++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 .github/workflows/build-img.yml create mode 100644 Full.Dockerfile diff --git a/.github/workflows/build-img.yml b/.github/workflows/build-img.yml new file mode 100644 index 00000000..af8c2d59 --- /dev/null +++ b/.github/workflows/build-img.yml @@ -0,0 +1,50 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - refactor + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Full.Dockerfile # Specify the Dockerfile to use + push: true + tags: | + type=raw,value={{sha}} + type=raw,value=latest + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Full.Dockerfile b/Full.Dockerfile new file mode 100644 index 00000000..bb07d4e7 --- /dev/null +++ b/Full.Dockerfile @@ -0,0 +1,66 @@ +# Use the latest official Rust image as the base +FROM rust:latest + +# Use bash as the shell +SHELL ["/bin/bash", "-c"] + +# Install NVM, Node.js, and Yarn +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash \ + && . $HOME/.nvm/nvm.sh \ + && nvm install 18 \ + && nvm alias default 18 \ + && nvm use default \ + && npm install -g yarn + +# Set the working directory +WORKDIR /relayer + +# Pre-configure Git to avoid common issues and increase clone verbosity +RUN git config --global advice.detachedHead false \ + && git config --global core.compression 0 \ + && git config --global protocol.version 2 \ + && git config --global http.postBuffer 1048576000 \ + && git config --global fetch.verbose true + +# Copy project files +COPY . . + +# Remove the packages/relayer directory +RUN rm -rf packages/relayer + +# Install Yarn dependencies with retry mechanism +RUN . $HOME/.nvm/nvm.sh && nvm use default && yarn || \ + (sleep 5 && yarn) || \ + (sleep 10 && yarn) + +# Install Foundry +RUN curl -L https://foundry.paradigm.xyz | bash \ + && source $HOME/.bashrc \ + && foundryup + +# Verify Foundry installation +RUN source $HOME/.bashrc && forge --version + +# Set the working directory for contracts +WORKDIR /relayer/packages/contracts + +# Install Yarn dependencies for contracts +RUN source $HOME/.nvm/nvm.sh && nvm use default && yarn + +# Build the contracts using Foundry +RUN source $HOME/.bashrc && forge build + +# Copy the project files +COPY packages/relayer /relayer/packages/relayer + +# Set the working directory for the Rust project +WORKDIR /relayer/packages/relayer + +# Build the Rust project with caching +RUN cargo build + +# Expose port +EXPOSE 4500 + +# Set the default command +CMD ["cargo", "run"]