Skip to content

Commit

Permalink
feat(internal-dashboard): adding job for building dashboard (#278)
Browse files Browse the repository at this point in the history
* adding job for building dashboard

* adding checkout step

* spliting into two MR's

* fixing paths

* Github Action: Bazel Repin

* changing how the files are uploaded

* updating comment

* updating sha of ic-icrc1

* adding pwd

* adding status print

* adding sha

* changing to use env variable

* adding sha for calculation

* increasing git fetch depth

* changing to correct symbols

* adding better debug print

* updating to non-legacy options

* converting

* fixing

* reenabling whole main

* using files instead of variable

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
NikolaMilosa and github-actions[bot] committed Apr 4, 2024
1 parent 89d7dd2 commit 0abe44a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 3 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/check-modified-files-as-step/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Check if a path was modified
description: Reusable action for checking if a file path is modified as a step. It outputs a `changed` variable which can be referenced later.

inputs:
path:
description: 'Path to check'
required: true

runs:
using: composite
steps:
########################################
# Check to see if files changed
########################################
- name: "🔍 Check if $PATH_TO_CHECK is modified in last commit "
env:
PATH_TO_CHECK: ${{ inputs.path }}
shell: bash
run: |
set -eExou pipefail
echo "=============== list modified files ==============="
git diff --name-only HEAD^ HEAD
echo "========== check paths of modified files =========="
git diff --name-only HEAD^ HEAD > files.txt
while IFS= read -r file
do
echo $file
if [[ $file != $PATH_TO_CHECK ]]; then
echo "changed=false" >> $GITHUB_ENV
else
echo "File $file matches $PATH_TO_CHECK"
echo "changed=true" >> $GITHUB_ENV
break
fi
done < files.txt
34 changes: 34 additions & 0 deletions .github/workflows/dashboard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build and push dashboard image
on:
push:
paths:
- dashboard
branches:
- "main"
pull_request:
merge_group:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: "🚀 Building"
run: |
docker build -t ghcr.io/dfinity/dre/ic-management-frontend:$GITHUB_SHA -f dashboard/Dockerfile dashboard
- name: "🔧 Login to GitHub Container Registry"
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: "📦 Push images to GitHub Container Registry"
if: ${{ startsWith(github.head_ref, 'container') || startsWith(github.ref, 'refs/heads/container') || (github.ref == 'refs/heads/main') }}
run: |
docker push ghcr.io/dfinity/dre/ic-management-frontend:$GITHUB_SHA
34 changes: 34 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: "☁️ Setup runner"
uses: ./.github/workflows/manage-runner-pre

Expand Down Expand Up @@ -65,6 +67,35 @@ jobs:
if: ${{ startsWith(github.ref, 'refs/tags/v') || startsWith(github.head_ref, 'container') || startsWith(github.ref, 'refs/heads/container') || (github.ref == 'refs/heads/main') }}
run: bazel query --noshow_progress 'kind("oci_push", ...)' | xargs -I_target bazel run _target -- --tag ${GITHUB_SHA}

########################################
# Check if dashboard/* changed to see if
# it also needs to be updated in k8s
########################################
- name: "❓ Check if dashboard/* changed in last commit"
id: check
uses: ./.github/workflows/check-modified-files-as-step
with:
path: dashboard/*

- name: "💲 Setting correct paths to update"
id: paths
shell: bash
run: |
files=(
bases/apps/mainnet-dashboard/statefulset-slack.yaml
bases/apps/mainnet-dashboard/backend/base/deployment.yaml
)
if [[ $changed == "true" ]]; then
echo "Adding frontend to list of files"
files+=( bases/apps/mainnet-dashboard/frontend/deployment.yaml )
else
echo "Skipping adding of frontend to list of files"
fi
echo "Output of this step:"
echo ${files[@]}
echo "files=${files[@]}" >> $GITHUB_ENV
########################################
# Update k8s deployments
########################################
Expand All @@ -74,6 +105,9 @@ jobs:
with:
gitlab_api_token: ${{ secrets.GITLAB_K8S_API_TOKEN }}

########################################
# Deploy to github pages
########################################
- name: "🚢 Deploy to GitHub Pages"
if: ${{ github.ref == 'refs/heads/main' }}
run: |
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/update-k8s-deployments/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ runs:
run: |
set -eExou pipefail
echo "Should change following files:"
echo $files
cd .git
# checkout branch
Expand All @@ -30,7 +33,7 @@ runs:
# this regex matches the first group (ie the image name) and uses \1
# called a back-reference to insert the first group matched, the second
# part is to match the 40 characters hash that we replace with the $GITHUB_SHA
sed -i "s~\(\([[:alpha:]]\|-\)\+\):[[:alnum:]]\{40\}~\1:${GITHUB_SHA}~g" bases/apps/mainnet-dashboard/statefulset-slack.yaml bases/apps/mainnet-dashboard/backend/base/deployment.yaml bases/apps/mainnet-dashboard/frontend/deployment.yaml
sed -i "s~\(\([[:alpha:]]\|-\)\+\):[[:alnum:]]\{40\}~\1:${GITHUB_SHA}~g" $files
# commit changes if there are any
git add .
Expand Down
4 changes: 2 additions & 2 deletions dashboard/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ services:
dashboard-backend-mainnet:
build:
context: ..
dockerfile: ic-management-backend/Dockerfile
dockerfile: rs/ic-management-backend/Dockerfile
args:
BUILDKIT_INLINE_CACHE: 1
slack:
build:
context: ..
dockerfile: slack-notifications/Dockerfile
dockerfile: rs/slack-notifications/Dockerfile
args:
BUILDKIT_INLINE_CACHE: 1

0 comments on commit 0abe44a

Please sign in to comment.