Skip to content

Commit 20f67cd

Browse files
author
Skylar Simoncelli
committed
feat: modular ghcr
1 parent fba186f commit 20f67cd

File tree

2 files changed

+37
-124
lines changed

2 files changed

+37
-124
lines changed

.github/workflows/cicd.yml

+5-106
Original file line numberDiff line numberDiff line change
@@ -467,109 +467,8 @@ jobs:
467467
echo "All pods are 4/4 up and ready"
468468
469469
publish-ghcr-image:
470-
runs-on: ubuntu-latest
471-
permissions:
472-
contents: write
473-
packages: write
474-
steps:
475-
- name: Checkout
476-
uses: actions/checkout@v4
477-
with:
478-
ref: ${{ github.event.inputs.partner-chains-sha }}
479-
480-
- name: Setup Earthly
481-
uses: ./.github/earthly-setup
482-
with:
483-
ssh_key: ${{ secrets.SUBSTRATE_REPO_SSH_KEY }}
484-
config_tar: ${{ secrets.EARTHLY_TAR }}
485-
486-
- name: Build and Benchmark
487-
env:
488-
EARTHLY_CI: true
489-
run: |
490-
export EARTHLY_OUTPUT=true
491-
earthly -P +build --PROFILE=production --FEATURES=runtime-benchmarks
492-
493-
- name: Generate and Extract Weights
494-
continue-on-error: true
495-
run: |
496-
repository_name="${GITHUB_REPOSITORY##*/}"
497-
echo "Listing contents on the runner host in /home/runner/work/${repository_name}/${repository_name}:"
498-
ls -la /home/runner/work/${repository_name}/${repository_name}
499-
echo "Pulling Docker image..."
500-
docker pull ubuntu:22.04
501-
mkdir -p weights
502-
echo "Running Docker container..."
503-
docker run -d --name weight_generation \
504-
--memory=4096m \
505-
--cpus=1 \
506-
-v /home/runner/work/${repository_name}/${repository_name}:/workspace \
507-
ubuntu:22.04 \
508-
/bin/bash -c "sleep infinity"
509-
echo "Installing necessary packages inside the container..."
510-
docker exec weight_generation bash -c "\
511-
apt-get update && \
512-
apt-get install -y jq curl build-essential && \
513-
echo 'Checking files in workspace...' && \
514-
ls -la /workspace && \
515-
mkdir -p /workspace/target/production && \
516-
cp /workspace/sidechains-substrate-node /workspace/target/production/sidechains-substrate-node && \
517-
echo 'Verifying the binary is in the expected path...' && \
518-
ls -la /workspace/target/production && \
519-
cd /workspace && \
520-
echo 'Setting the current working directory to /workspace...' && \
521-
chmod +x scripts/run_all_pallet_overhead_and_machine_benchmarks.sh && \
522-
chmod +x scripts/run_storage_benchmarks.sh && \
523-
source .envrc || true && \
524-
./scripts/run_all_pallet_overhead_and_machine_benchmarks.sh -b && \
525-
./scripts/run_storage_benchmarks.sh -b || true"
526-
echo "Finding and copying weight files..."
527-
weight_files=$(docker exec weight_generation find /workspace/runtime/src/weights -name '*.rs')
528-
echo "$weight_files" | while read weight_file; do
529-
weight_file_name=$(basename "$weight_file")
530-
echo "Copying ${weight_file_name}"
531-
docker cp "weight_generation:$weight_file" "weights/${weight_file_name}"
532-
done
533-
docker stop weight_generation
534-
docker rm weight_generation
535-
536-
- name: Overwrite Weights in Runtime Directory
537-
continue-on-error: true
538-
run: |
539-
sudo chmod -R a+rwx ./runtime/src/weights
540-
for weight_file in weights/*.rs
541-
do
542-
cp "$weight_file" "./runtime/src/weights/$(basename "$weight_file")"
543-
done
544-
545-
- name: Main Build
546-
if: ${{ inputs.publish_to_ghcr }}
547-
env:
548-
EARTHLY_CI: true
549-
EARTHLY_PUSH: false
550-
EARTHLY_OUTPUT: true
551-
run: earthly -P +docker --image="ghcr-image" --tags="latest"
552-
553-
- name: Login to GitHub Container Registry
554-
uses: docker/login-action@v3
555-
with:
556-
registry: ghcr.io
557-
username: ${{ github.actor }}
558-
password: ${{ secrets.GITHUB_TOKEN }}
559-
logout: true
560-
env:
561-
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
562-
FORCE_COLOR: 1
563-
564-
- name: Tag and Push Image to GHCR
565-
run: |
566-
repository_name="${GITHUB_REPOSITORY##*/}"
567-
target_image="ghcr.io/${{ github.repository }}/$repository_name-node"
568-
569-
docker tag ghcr-image:latest $target_image:latest
570-
docker tag ghcr-image:latest $target_image:${{ github.event.inputs.partner-chains-sha }}
571-
docker tag ghcr-image:latest $target_image:${{ github.event.inputs.partner-chains-tag }}
572-
573-
docker push $target_image:latest
574-
docker push $target_image:${{ github.event.inputs.partner-chains-sha }}
575-
docker push $target_image:${{ github.event.inputs.partner-chains-tag }}
470+
uses: ./.github/workflows/modules/build-and-publish-ghcr-image.yml
471+
with:
472+
commit_sha: ${{ github.event.inputs.partner-chains-sha }}
473+
ghcr_tag: ${{ github.event.inputs.partner-chains-tag }}
474+
publish_to_ghcr: true

.github/workflows/ghcr.yml .github/workflows/modules/build-and-publish-ghcr-image.yml

+32-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1-
name: Build and Publish to GHCR Public Repository
1+
name: Build and Publish to GHCR
22

33
on:
4-
5-
workflow_dispatch:
6-
inputs:
7-
commit_sha:
8-
description: 'Commit SHA to build from'
9-
required: true
10-
type: string
11-
publish_to_ghcr:
12-
description: "Publish to GitHub Container Registry"
13-
default: true
14-
type: boolean
15-
ghcr_tag:
16-
description: "Tag for GHCR image"
17-
required: true
18-
type: string
4+
workflow_call:
5+
inputs:
6+
commit_sha:
7+
description: 'Commit SHA to build from'
8+
required: true
9+
type: string
10+
ghcr_tag:
11+
description: "Tag for GHCR image"
12+
required: true
13+
type: string
14+
publish_to_ghcr:
15+
description: "Publish to GitHub Container Registry"
16+
default: true
17+
type: boolean
18+
19+
workflow_dispatch:
20+
inputs:
21+
commit_sha:
22+
description: 'Commit SHA to build from'
23+
required: true
24+
type: string
25+
ghcr_tag:
26+
description: "Tag for GHCR image"
27+
required: true
28+
type: string
29+
publish_to_ghcr:
30+
description: "Publish to GitHub Container Registry"
31+
default: true
32+
type: boolean
1933

2034
env:
2135
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
@@ -31,7 +45,7 @@ jobs:
3145
- name: Checkout
3246
uses: actions/checkout@v4
3347
with:
34-
ref: ${{ github.event.inputs.commit_sha }}
48+
ref: ${{ inputs.commit_sha }}
3549

3650
- name: Setup Earthly
3751
uses: ./.github/earthly-setup
@@ -121,7 +135,7 @@ jobs:
121135
run: |
122136
repository_name="${GITHUB_REPOSITORY##*/}"
123137
target_image="ghcr.io/${{ github.repository }}/$repository_name-node"
124-
commit_sha="${{ github.event.inputs.commit_sha }}"
138+
commit_sha="${{ inputs.commit_sha }}"
125139
custom_tag="${{ inputs.ghcr_tag }}"
126140
127141
docker tag ghcr-image:latest $target_image:latest

0 commit comments

Comments
 (0)