Skip to content

Commit

Permalink
Merge pull request #2296 from johnny-morrice/feature/master-build
Browse files Browse the repository at this point in the history
Dockerized build scripts for the master branch
  • Loading branch information
g-leech authored Feb 16, 2025
2 parents 149cac9 + 05f8b73 commit 09d2b24
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 20 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/deploy-cloudflare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build & Deploy to Cloudflare

on:
# 1. Manual trigger via the Actions tab
workflow_dispatch:
inputs:
branch:
description: "Branch to build and deploy"
required: false
default: "master"
inputs:
environment:
description: "Environment to deploy to"
required: false
default: "development"

jobs:
build-and-deploy:
name: Build and Deploy to Cloudflare
runs-on: ubuntu-latest

# 2. Use the environment input to set the environment
# so that environment-scoped secrets are available
environment: ${{ github.event.inputs.environment }}

steps:
# 3. Check out the specified branch
- name: Check out code
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}

# 4. Build the site using your existing Docker build script
- name: Build the site using Docker
run: |
./scripts/build.sh
# 5. Deploy to Cloudflare using the Cloudflare Wrangler Action
- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
environment: ${{ github.event.inputs.environment }}
workingDirectory: "_site"
11 changes: 8 additions & 3 deletions .github/workflows/deploy-netlify.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Manual Build & Deploy to Netlify (Dev)
name: Build & Deploy to Netlify

on:
# 1. Manual trigger via the Actions tab
Expand All @@ -8,15 +8,20 @@ on:
description: "Branch to build and deploy"
required: false
default: "master"
inputs:
environment:
description: "Environment to deploy to"
required: false
default: "development"

jobs:
build-and-deploy:
name: Build and Deploy to Netlify
runs-on: ubuntu-latest

# 2. Use the environment named 'Dev'
# 2. Use the environment input to set the environment
# so that environment-scoped secrets are available
environment: Dev
environment: ${{ github.event.inputs.environment }}

steps:
# 3. Check out the specified branch
Expand Down
14 changes: 14 additions & 0 deletions Dockerfiles/Dockerfile.bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM jekyll/jekyll:4.0

# Create a working directory.
WORKDIR /srv/jekyll

# Copy dependency files first for caching.
COPY Gemfile ./

# Make files be owned by jekyll user.
RUN chown -R jekyll:jekyll /srv/jekyll

# Update the bundle and add the current platform lock.
RUN bundle lock

34 changes: 34 additions & 0 deletions Dockerfiles/Dockerfile.jekyll
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Use Ruby 3.1 series on Alpine.
FROM ruby:3.1-alpine

# Install system dependencies.
# (Node.js is here for asset compilation, adjust as needed.)
RUN apk update && apk add --no-cache \
build-base \
nodejs \
libffi-dev

# Install bundler if it’s not already available.
RUN gem install bundler -v 2.3.25

# Set working directory.
WORKDIR /srv/jekyll

# Copy Gemfiles (so that dependencies are installed during image build).
COPY Gemfile Gemfile.lock ./

# Install Ruby dependencies as specified in the Gemfile.
RUN bundle install

# Copy the rest of the project files.
# When running interactively you will mount your project folder over this.
COPY . .

# Expose the default Jekyll port.
EXPOSE 4000

ENV JEKYLL_ENV=docker

# Run the Jekyll server with incremental rebuilds and bind to localhost.
CMD ["bundle", "exec", "jekyll", "serve", "--incremental", "--host", "0.0.0.0", "--config", "_config_docker.yml"]

3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# A sample Gemfile
source "https://rubygems.org"

gem "jekyll"
ruby '~> 3.1.1'
gem "jekyll", "~> 4.3.3"

gem "jekyll-sass-converter", "~> 2.0"
gem "webrick", "~> 1.8"
34 changes: 18 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ GEM
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
colorator (1.1.0)
concurrent-ruby (1.3.3)
concurrent-ruby (1.3.5)
em-websocket (0.5.3)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
eventmachine (1.2.7)
ffi (1.16.3)
ffi (1.17.1-aarch64-linux-musl)
ffi (1.17.1-x86_64-linux-musl)
forwardable-extended (2.6.0)
http_parser.rb (0.8.0)
i18n (1.14.5)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
jekyll (4.3.3)
jekyll (4.3.4)
addressable (~> 2.4)
colorator (~> 1.0)
em-websocket (~> 0.5)
Expand All @@ -34,8 +35,8 @@ GEM
sassc (> 2.0.1, < 3.0)
jekyll-watch (2.2.1)
listen (~> 3.0)
kramdown (2.4.0)
rexml
kramdown (2.5.1)
rexml (>= 3.3.9)
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
liquid (4.0.4)
Expand All @@ -49,26 +50,27 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rexml (3.3.2)
strscan
rouge (4.3.0)
rexml (3.4.0)
rouge (4.5.1)
safe_yaml (1.0.5)
sassc (2.4.0)
ffi (~> 1.9)
strscan (3.1.0)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
unicode-display_width (2.5.0)
webrick (1.8.1)
unicode-display_width (2.6.0)
webrick (1.9.1)

PLATFORMS
aarch64-linux-gnu
ruby
aarch64-linux-musl
x86_64-linux-musl

DEPENDENCIES
jekyll
jekyll (~> 4.3.3)
jekyll-sass-converter (~> 2.0)
webrick (~> 1.8)

RUBY VERSION
ruby 3.1.1p18

BUNDLED WITH
2.1.4
2.3.25
11 changes: 11 additions & 0 deletions _config_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Site settings
title: argmin gravitas
fmtTitle: argmin gravitas
email: g@gleech.org
baseurl: "" # the subpath of your site, e.g. /blog/
url: http://localhost:4000 # the base hostname & protocol for your site
github_username: g-leech
highlighter: none

# Build settings
markdown: kramdown
12 changes: 12 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

echo "Building Docker image for static site generation..."
docker build --platform=linux/amd64 -t argmin-gravitas/jekyll-dev -f Dockerfiles/Dockerfile.jekyll .

echo "Generating static site..."
# Mount your local "./_site" directory to the container's /srv/jekyll/_site directory.
mkdir -p _site
docker run --platform=linux/amd64 -v "$(pwd)/_site:/srv/jekyll/_site" argmin-gravitas/jekyll-dev bundle exec jekyll build

echo "Site built successfully into the ./_site directory."
21 changes: 21 additions & 0 deletions scripts/bundle-lock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e

# Define image name and Dockerfile path.
IMAGE_NAME="gemfile_updater"
DOCKERFILE="Dockerfiles/Dockerfile.bundle"

echo "Building the Docker image"
docker build -t ${IMAGE_NAME} -f ${DOCKERFILE} .

# Create a container from the builder image.
CONTAINER_ID=$(docker create ${IMAGE_NAME})

# Copy the Gemfile.lock from the container to the host.
echo "Copying updated Gemfile.lock from container (${CONTAINER_ID})..."
docker cp "${CONTAINER_ID}:/srv/jekyll/Gemfile.lock" ./Gemfile.lock

# Clean up the temporary container.
docker rm ${CONTAINER_ID} > /dev/null

echo "Updated Gemfile.lock has been copied to the host."
9 changes: 9 additions & 0 deletions scripts/dev-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

echo "Building Docker image for Jekyll development..."
docker build -t argmin-gravitas/jekyll-dev -f Dockerfiles/Dockerfile.jekyll .

echo "Running Docker container with live file editing enabled..."
# The -v flag mounts the current directory (source code) into /srv/jekyll in the container.
docker run -p 4000:4000 -v "$(pwd)":/srv/jekyll argmin-gravitas/jekyll-dev

0 comments on commit 09d2b24

Please sign in to comment.