-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github actions to build docker image
- Loading branch information
Showing
2 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Use the latest official Rust image as the base | ||
FROM rust:latest AS base | ||
|
||
# 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 | ||
|
||
# Pre-configure Git | ||
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 | ||
|
||
# Install Foundry | ||
RUN curl -L https://foundry.paradigm.xyz | bash \ | ||
&& . $HOME/.bashrc \ | ||
&& foundryup | ||
|
||
# Verify Foundry installation | ||
RUN . $HOME/.bashrc && forge --version | ||
|
||
# Stage for building contracts | ||
FROM base AS contract-builder | ||
|
||
# Set the working directory | ||
WORKDIR /relayer | ||
|
||
# Copy only the files needed for contract building | ||
COPY packages/contracts/package.json packages/contracts/yarn.lock ./packages/contracts/ | ||
COPY package.json yarn.lock ./ | ||
|
||
# Install dependencies | ||
RUN . $HOME/.nvm/nvm.sh && nvm use default && yarn install --frozen-lockfile | ||
|
||
# Copy contract source files | ||
COPY packages/contracts ./packages/contracts | ||
|
||
# Build the contracts | ||
WORKDIR /relayer/packages/contracts | ||
RUN . $HOME/.bashrc && forge build | ||
|
||
# Stage for building the relayer | ||
FROM base AS relayer-builder | ||
|
||
# Set the working directory | ||
WORKDIR /relayer/packages/relayer | ||
|
||
# Copy the Cargo.toml and Cargo.lock files | ||
COPY packages/relayer/Cargo.toml packages/relayer/Cargo.lock ./ | ||
|
||
# Create a dummy main.rs to build dependencies | ||
RUN mkdir src && echo "fn main() {}" > src/main.rs | ||
|
||
# Build dependencies | ||
RUN cargo build | ||
|
||
# Remove the dummy file | ||
RUN rm src/main.rs | ||
|
||
# Copy the actual source code | ||
COPY packages/relayer/src ./src | ||
|
||
# Build the actual application | ||
RUN cargo build | ||
|
||
# Final stage | ||
FROM base AS final | ||
|
||
# Set the working directory | ||
WORKDIR /relayer | ||
|
||
# Copy built artifacts from previous stages | ||
COPY --from=contract-builder /relayer/packages/contracts ./packages/contracts | ||
COPY --from=relayer-builder /relayer/packages/relayer/target ./packages/relayer/target | ||
|
||
# Set the working directory for the Rust project | ||
WORKDIR /relayer/packages/relayer | ||
|
||
# Expose port | ||
EXPOSE 4500 | ||
|
||
# Set the default command | ||
CMD ["cargo", "run"] |