Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Jekyll-based build for Vespa Search #12

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Docker

# This workflow will generate container images for each of the Github Actions
# which are using a Dockerfile.

on:
push:
branches:
- "main"
- "feature-*"
pull_request:
branches:
- "main"

jobs:
prepare:
# Finds all the Dockerfiles in the repository and sets the action names
# as output to reuse as matrix strategy in the build job
runs-on: ubuntu-latest

outputs:
container_names_json: ${{ steps.set-output.outputs.container_names_json }}

steps:
- uses: actions/checkout@v4

- name: Find Dockerfiles
id: set-output
run: |
# Find all Dockerfiles in the repository
paths_with_docker=$(find -type f -name 'Dockerfile' | sed 's|/Dockerfile||' | sed 's|./||')
# Transform the list of paths into a valid JSON array to be used as matrix strategy
action_names=$(echo $paths_with_docker | jq --raw-input --compact-output 'split(" ") | . ')

echo "Found Dockerfiles in the repository:"
echo "${action_names}"

echo "container_names_json=${action_names}" >> "${GITHUB_OUTPUT}"

build:
runs-on: ubuntu-latest

needs:
- prepare

permissions:
contents: read
packages: write

strategy:
matrix:
action-name: ${{fromJson(needs.prepare.outputs.container_names_json)}}
docker-platform: [linux/amd64, linux/arm64]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/${{ matrix.action-name }}

steps:
- uses: actions/checkout@v4

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=pr
type=ref,event=branch
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ${{ matrix.action-name }}
file: ${{ matrix.action-name }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.docker-platform }}
cache-from: type=gha
cache-to: type=gha,mode=max
33 changes: 33 additions & 0 deletions .github/workflows/jekyll-feed-to-vespa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: (WIP) Feed Jekyll posts to Vespa

on:
workflow_call:
inputs:
log_level:
description: 'Log level for Jekyll build.'
required: false
default: 'info'
type: string

defaults:
run:
# Specify to ensure "pipefail and errexit" are set.
# Ref: https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#defaultsrunshell
shell: bash

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Build with Jekyll
uses: vespa-engine/gh-actions/jekyll-build-json@main
with:
log_level: ${{ github.event.inputs.log_level }}

- name: List JSON
run: |
find _site -type f -name '*.json'
30 changes: 30 additions & 0 deletions jekyll-build-json/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ARG RUBY_VERSION=3.3
FROM ruby:$RUBY_VERSION-slim

RUN apt-get update \
&& apt-get install -y \
build-essential \
git \
locales

COPY Gemfile Gemfile

ENV NOKOGIRI_USE_SYSTEM_LIBRARIES=true

RUN gem env && \
bundle install --jobs 20 --retry 5

RUN \
echo "en_US UTF-8" > /etc/locale.gen && \
locale-gen en-US.UTF-8

ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8

COPY entrypoint.sh /entrypoint.sh

RUN mkdir -p /opt/jekyll/plugins
COPY vespa_index_generator.rb /opt/jekyll/plugins/vespa_index_generator.rb

ENTRYPOINT ["/entrypoint.sh"]
17 changes: 17 additions & 0 deletions jekyll-build-json/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
# frozen_string_literal: true

source "https://rubygems.org"

# Manage our dependency on the version of the github-pages gem here.
gem "github-pages", "= 232"

# Explicitly include this gem here.
# It is not directly included in the github-pages gem list of dependencies,
# even though it is included in the original GitHub Pages build infrastructure.
gem "jekyll-include-cache", "= 0.2.1"
gem "jekyll-octicons", "~> 14.2"
gem "minima", "~> 2.0"

# Work-around for webrick no longer included in Ruby 3.0 (https://github.com/jekyll/jekyll/issues/8523)
gem "webrick"
27 changes: 27 additions & 0 deletions jekyll-build-json/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'Build Jekyll for Vespa Search'
description: 'A simple GH Action for producing Jekyll build artifacts compatible with Vespa JSON'
author: 'Vespa.ai'
inputs:
source:
description: 'Directory where the source files reside (relative to the workspace).'
required: false
default: ./
destination:
description: 'Output directory of the build. Although it can be nested inside the source, it cannot be the same as the source directory (relative to the workspace).'
required: false
default: ./_site
config:
description: 'Jekyll configuration file path relative to the workspace root.'
required: false
default: ./_config.yml
log_level:
description: 'Log level for Jekyll build.'
required: false
default: 'info'
token:
description: 'GitHub token'
required: true
default: ${{ github.token }}
runs:
using: 'docker'
image: 'docker://ghcr.io/vespa-engine/gh-actions/jekyll-build-json'
58 changes: 58 additions & 0 deletions jekyll-build-json/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

if [[ "${RUNNER_DEBUG:-}" == "1" ]]; then
set -x
fi

set -e
set -o pipefail
set -o nounset

SOURCE_DIRECTORY="${GITHUB_WORKSPACE}/${INPUT_SOURCE}"
DESTINATION_DIRECTORY="${GITHUB_WORKSPACE}/${INPUT_DESTINATION}"
JEKYLL_CONFIG_FILE="${GITHUB_WORKSPACE}/${INPUT_CONFIG}"
JEKYLL_ARGS=("-p" "/opt/jekyll/plugins")

# Set environment variables required by supported plugins
export JEKYLL_ENV="production"
export JEKYLL_GITHUB_TOKEN="${INPUT_TOKEN}"
export JEKYLL_BUILD_REVISION="${GITHUB_SHA}"
export JEKYLL_LOG_LEVEL="${INPUT_LOG_LEVEL}"

if [[ "${JEKYLL_LOG_LEVEL}" = "verbose" || "${JEKYLL_LOG_LEVEL}" = "debug" ]]; then
JEKYLL_ARGS+=("-V")
fi

if [[ "${RUNNER_DEBUG:-}" == "1" ]]; then
gem env
bundle env

echo "SOURCE_DIRECTORY: ${SOURCE_DIRECTORY}"
echo "DESTINATION_DIRECTORY: ${DESTINATION_DIRECTORY}"
echo "JEKYLL_CONFIG_FILE: ${JEKYLL_CONFIG_FILE}"
echo "GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"

echo "====== START Config file ====="
cat "${JEKYLL_CONFIG_FILE}"
echo "====== END Config file ====="
fi

{ cd "${BUNDLE_APP_CONFIG}" || { echo "::error::pages gem not found"; exit 1; }; }

# Run the command, capturing the output
build_output="$(bundle exec jekyll build ${JEKYLL_ARGS[@]} --config "${JEKYLL_CONFIG_FILE}" --source "${SOURCE_DIRECTORY}" --destination "${DESTINATION_DIRECTORY}")"

# Capture the exit code
exit_code=$?

if [ $exit_code -ne 0 ]; then
# Remove the newlines from the build_output as annotation not support multiline
error=$(echo "$build_output" | tr '\n' ' ' | tr -s ' ')
echo "::error::$error"
else
# Display the build_output directly
echo "$build_output"
fi

# Exit with the captured exit code
exit $exit_code
Loading
Loading