Skip to content

Personalized health technologies workshop #169

Personalized health technologies workshop

Personalized health technologies workshop #169

# Workflow for making a preview deployment of the blog
name: Deploy blog preview
on:
pull_request:
types:
- opened
- synchronize
- reopened
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
# Default to bash
defaults:
run:
shell: bash
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# Build job
build:
if: ${{ github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
outputs:
image: ${{ steps.docker_image.outputs.image }}
image_repository: ${{ steps.docker_image.outputs.image_repository }}
image_tag: ${{ steps.docker_image.outputs.image_tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: type=sha
- name: Extract Docker image name
id: docker_image
env:
IMAGE_TAGS: ${{ steps.meta.outputs.tags }}
run: |
IMAGE=$(echo "$IMAGE_TAGS" | cut -d" " -f1)
IMAGE_REPOSITORY=$(echo "$IMAGE" | cut -d":" -f1)
IMAGE_TAG=$(echo "$IMAGE" | cut -d":" -f2)
echo "image=$IMAGE" >> "$GITHUB_OUTPUT"
echo "image_repository=$IMAGE_REPOSITORY" >> "$GITHUB_OUTPUT"
echo "image_tag=$IMAGE_TAG" >> "$GITHUB_OUTPUT"
- name: Set up node
uses: actions/setup-node@v4
with:
node-version: "20.17.0"
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: Set up Docker
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: npm clean-install
- name: Build site
run: npm run build
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ steps.docker_image.outputs.image_repository }}:buildcache
cache-to: type=registry,ref=${{ steps.docker_image.outputs.image_repository }}:buildcache,mode=max
deploy:
# Deploy job
if: ${{ github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
needs: [build]
environment:
name: renku-blog-ci-${{ github.event.number }}
url: https://renku-blog-ci-${{ github.event.number }}.dev.renku.ch
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Helm
uses: azure/setup-helm@v4
- name: Deploy helm chart
env:
RELEASE: renku-blog-ci-${{ github.event.number }}
KUBECONFIG: "${{ github.workspace }}/renkubot-kube.config"
RENKUBOT_KUBECONFIG: ${{ secrets.RENKUBOT_DEV_KUBECONFIG }}
run: |
NAMESPACE=${RELEASE}
HOST=renku-blog-ci-${{ github.event.number }}.dev.renku.ch
IMAGE=$(echo "$IMAGE_TAGS" | cut -d" " -f1)
IMAGE_REPOSITORY=${{ needs.build.outputs.image_repository }}
IMAGE_TAG=${{ needs.build.outputs.image_tag }}
echo "$RENKUBOT_KUBECONFIG" > "$KUBECONFIG" && chmod 400 "$KUBECONFIG"
kubectl create namespace ${NAMESPACE} || true
helm upgrade --install ${RELEASE} ./helm-chart/renku-blog \
--namespace=${NAMESPACE} --timeout 5m --wait --wait-for-jobs \
--set image.repository=${IMAGE_REPOSITORY} --set image.tag=${IMAGE_TAG} \
--set ingress.enabled=true --set ingress.hosts[0].host=${HOST} \
--set ingress.hosts[0].paths[0].path="/" --set ingress.hosts[0].paths[0].pathType="Prefix" \
--set ingress.tls[0].secretName="${RELEASE}-tls" \
--set ingress.tls[0].hosts[0]=${HOST}
- name: Find deployment comment
uses: peter-evans/find-comment@v3
id: find_comment
with:
issue-number: ${{ github.event.pull_request.number }}
# comment-author: "RenkuBot"
comment-author: "github-actions[bot]"
body-includes: You can access the deployment of this PR at
- name: Deployment comment
if: steps.find_comment.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v4
with:
# token: ${{ secrets.RENKUBOT_GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
You can access the deployment of this PR at https://renku-blog-ci-${{ github.event.number }}.dev.renku.ch
reactions: "rocket"