Skip to content

Commit

Permalink
feat: modular ghcr
Browse files Browse the repository at this point in the history
  • Loading branch information
Skylar Simoncelli committed Sep 17, 2024
1 parent fba186f commit 20f67cd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 124 deletions.
111 changes: 5 additions & 106 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -467,109 +467,8 @@ jobs:
echo "All pods are 4/4 up and ready"
publish-ghcr-image:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.partner-chains-sha }}

- name: Setup Earthly
uses: ./.github/earthly-setup
with:
ssh_key: ${{ secrets.SUBSTRATE_REPO_SSH_KEY }}
config_tar: ${{ secrets.EARTHLY_TAR }}

- name: Build and Benchmark
env:
EARTHLY_CI: true
run: |
export EARTHLY_OUTPUT=true
earthly -P +build --PROFILE=production --FEATURES=runtime-benchmarks
- name: Generate and Extract Weights
continue-on-error: true
run: |
repository_name="${GITHUB_REPOSITORY##*/}"
echo "Listing contents on the runner host in /home/runner/work/${repository_name}/${repository_name}:"
ls -la /home/runner/work/${repository_name}/${repository_name}
echo "Pulling Docker image..."
docker pull ubuntu:22.04
mkdir -p weights
echo "Running Docker container..."
docker run -d --name weight_generation \
--memory=4096m \
--cpus=1 \
-v /home/runner/work/${repository_name}/${repository_name}:/workspace \
ubuntu:22.04 \
/bin/bash -c "sleep infinity"
echo "Installing necessary packages inside the container..."
docker exec weight_generation bash -c "\
apt-get update && \
apt-get install -y jq curl build-essential && \
echo 'Checking files in workspace...' && \
ls -la /workspace && \
mkdir -p /workspace/target/production && \
cp /workspace/sidechains-substrate-node /workspace/target/production/sidechains-substrate-node && \
echo 'Verifying the binary is in the expected path...' && \
ls -la /workspace/target/production && \
cd /workspace && \
echo 'Setting the current working directory to /workspace...' && \
chmod +x scripts/run_all_pallet_overhead_and_machine_benchmarks.sh && \
chmod +x scripts/run_storage_benchmarks.sh && \
source .envrc || true && \
./scripts/run_all_pallet_overhead_and_machine_benchmarks.sh -b && \
./scripts/run_storage_benchmarks.sh -b || true"
echo "Finding and copying weight files..."
weight_files=$(docker exec weight_generation find /workspace/runtime/src/weights -name '*.rs')
echo "$weight_files" | while read weight_file; do
weight_file_name=$(basename "$weight_file")
echo "Copying ${weight_file_name}"
docker cp "weight_generation:$weight_file" "weights/${weight_file_name}"
done
docker stop weight_generation
docker rm weight_generation
- name: Overwrite Weights in Runtime Directory
continue-on-error: true
run: |
sudo chmod -R a+rwx ./runtime/src/weights
for weight_file in weights/*.rs
do
cp "$weight_file" "./runtime/src/weights/$(basename "$weight_file")"
done
- name: Main Build
if: ${{ inputs.publish_to_ghcr }}
env:
EARTHLY_CI: true
EARTHLY_PUSH: false
EARTHLY_OUTPUT: true
run: earthly -P +docker --image="ghcr-image" --tags="latest"

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: true
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
FORCE_COLOR: 1

- name: Tag and Push Image to GHCR
run: |
repository_name="${GITHUB_REPOSITORY##*/}"
target_image="ghcr.io/${{ github.repository }}/$repository_name-node"
docker tag ghcr-image:latest $target_image:latest
docker tag ghcr-image:latest $target_image:${{ github.event.inputs.partner-chains-sha }}
docker tag ghcr-image:latest $target_image:${{ github.event.inputs.partner-chains-tag }}
docker push $target_image:latest
docker push $target_image:${{ github.event.inputs.partner-chains-sha }}
docker push $target_image:${{ github.event.inputs.partner-chains-tag }}
uses: ./.github/workflows/modules/build-and-publish-ghcr-image.yml
with:
commit_sha: ${{ github.event.inputs.partner-chains-sha }}
ghcr_tag: ${{ github.event.inputs.partner-chains-tag }}
publish_to_ghcr: true
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
name: Build and Publish to GHCR Public Repository
name: Build and Publish to GHCR

on:

workflow_dispatch:
inputs:
commit_sha:
description: 'Commit SHA to build from'
required: true
type: string
publish_to_ghcr:
description: "Publish to GitHub Container Registry"
default: true
type: boolean
ghcr_tag:
description: "Tag for GHCR image"
required: true
type: string
workflow_call:
inputs:
commit_sha:
description: 'Commit SHA to build from'
required: true
type: string
ghcr_tag:
description: "Tag for GHCR image"
required: true
type: string
publish_to_ghcr:
description: "Publish to GitHub Container Registry"
default: true
type: boolean

workflow_dispatch:
inputs:
commit_sha:
description: 'Commit SHA to build from'
required: true
type: string
ghcr_tag:
description: "Tag for GHCR image"
required: true
type: string
publish_to_ghcr:
description: "Publish to GitHub Container Registry"
default: true
type: boolean

env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
Expand All @@ -31,7 +45,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.commit_sha }}
ref: ${{ inputs.commit_sha }}

- name: Setup Earthly
uses: ./.github/earthly-setup
Expand Down Expand Up @@ -121,7 +135,7 @@ jobs:
run: |
repository_name="${GITHUB_REPOSITORY##*/}"
target_image="ghcr.io/${{ github.repository }}/$repository_name-node"
commit_sha="${{ github.event.inputs.commit_sha }}"
commit_sha="${{ inputs.commit_sha }}"
custom_tag="${{ inputs.ghcr_tag }}"
docker tag ghcr-image:latest $target_image:latest
Expand Down

0 comments on commit 20f67cd

Please sign in to comment.