This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch HDDS-9225-website-v2
in repository https://gitbox.apache.org/repos/asf/ozone-site.git


The following commit(s) were added to refs/heads/HDDS-9225-website-v2 by this 
push:
     new dc3f5b2f HDDS-10352. Add GitHub Actions workflow to build and run the 
website. (#74)
dc3f5b2f is described below

commit dc3f5b2f2f368a3aa330e53610af5610b747066c
Author: Ethan Rose <[email protected]>
AuthorDate: Sun Feb 18 03:12:54 2024 -0800

    HDDS-10352. Add GitHub Actions workflow to build and run the website. (#74)
---
 .github/scripts/curl.sh                      | 25 +++++++
 .github/workflows/{docusaurus.yml => ci.yml} | 28 ++++----
 .github/workflows/docusaurus.yml             | 97 ++++++++++++++++++++++++----
 .github/workflows/publish.yml                | 78 +++++++++++-----------
 CONTRIBUTING.md                              |  2 +-
 Dockerfile                                   |  5 +-
 compose.yml                                  |  2 +-
 7 files changed, 164 insertions(+), 73 deletions(-)

diff --git a/.github/scripts/curl.sh b/.github/scripts/curl.sh
new file mode 100755
index 00000000..8c27ccce
--- /dev/null
+++ b/.github/scripts/curl.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env sh
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+echo 'Running website and checking homepage...'
+docker compose run --detach --service-ports site pnpm serve
+while [ "$(curl -so /dev/null -w '%{http_code}' http://localhost:3000)" != 200 
]; do
+  sleep 1;
+done
+echo 'Website homepage is responsive.'
diff --git a/.github/workflows/docusaurus.yml b/.github/workflows/ci.yml
similarity index 66%
copy from .github/workflows/docusaurus.yml
copy to .github/workflows/ci.yml
index 980e8af7..deff0b61 100644
--- a/.github/workflows/docusaurus.yml
+++ b/.github/workflows/ci.yml
@@ -13,28 +13,26 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-name: docusaurus
+# The main CI workflow for the Apache Ozone website.
+
+name: ci
 
 on:
   pull_request:
     types:
-      - opened
-      - synchronize
+    - opened
+    - synchronize
   push:
 
 concurrency:
-  group: docusaurus-${{ github.event.pull_request.number || github.sha }}
+  group: ci-${{ github.event.pull_request.number || github.sha }}
   cancel-in-progress: ${{ github.event_name == 'pull_request' }}
 
 jobs:
-  build:
-    runs-on: ubuntu-latest
-    steps:
-      - name: Checkout project
-        uses: actions/checkout@v4
-      - name: Build Docker image
-        run: |
-          docker compose build
-      - name: Run test
-        run: |
-          docker compose run site pnpm build
+  docusaurus:
+    uses: ./.github/workflows/docusaurus.yml
+  publish:
+    needs: docusaurus
+    # Update this to master when the website is ready to be published.
+    if: ${{ github.event == 'push' && github.ref_name == 
'HDDS-9225-website-v2' }}
+    uses: ./.github/workflows/publish.yml
diff --git a/.github/workflows/docusaurus.yml b/.github/workflows/docusaurus.yml
index 980e8af7..54257741 100644
--- a/.github/workflows/docusaurus.yml
+++ b/.github/workflows/docusaurus.yml
@@ -13,28 +13,97 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# Builds the website and runs tests using Docker.
+# The Docker image contains only pnpm prod dependencies, so it is cached.
+# The website build is stored as an artifact.
+
 name: docusaurus
 
 on:
-  pull_request:
-    types:
-      - opened
-      - synchronize
-  push:
+  workflow_call:
 
 concurrency:
   group: docusaurus-${{ github.event.pull_request.number || github.sha }}
   cancel-in-progress: ${{ github.event_name == 'pull_request' }}
 
+env:
+  script_dir: .github/scripts
+  image_tar: ozone-site-image.tar
+
 jobs:
-  build:
+  build-image:
+    runs-on: ubuntu-latest
+    steps:
+    - name: Checkout project
+      uses: actions/checkout@v4
+    - name: Check Docker image cache
+      id: cache
+      uses: actions/cache@v4
+      with:
+        path: ${{ env.image_tar }}
+        key: image-${{ hashFiles('Dockerfile', 'compose.yml', 
'pnpm-lock.yaml') }}
+        lookup-only: true
+    - name: Build Docker image
+      if: steps.cache.outputs.cache-hit != 'true'
+      run: |
+        docker compose build
+    - name: Save docker image to tar
+      if: steps.cache.outputs.cache-hit != 'true'
+      run: |
+        docker save ozone-site --output="${{ env.image_tar }}"
+    - name: Save docker image tar to cache
+      if: steps.cache.outputs.cache-hit != 'true'
+      uses: actions/cache/save@v4
+      with:
+        path: ${{ env.image_tar }}
+        key: image-${{ hashFiles('Dockerfile', 'compose.yml', 
'pnpm-lock.yaml') }}
+  build-website:
+    needs:
+    - build-image
+    runs-on: ubuntu-latest
+    steps:
+    - name: Checkout project
+      uses: actions/checkout@v4
+    - name: Restore docker image tar from cache
+      uses: actions/cache/restore@v4
+      with:
+        path: ${{ env.image_tar }}
+        key: image-${{ hashFiles('Dockerfile', 'compose.yml', 
'pnpm-lock.yaml') }}
+    - name: Load docker image
+      run: |
+        docker load --input="${{ env.image_tar }}"
+    - name: Build website
+      run: |
+        docker compose run site pnpm build
+    - name: Save website build artifact
+      uses: actions/upload-artifact@v4
+      with:
+        name: build
+        path: build
+        if-no-files-found: error
+        retention-days: 1
+  run-website:
+    needs:
+    - build-website
     runs-on: ubuntu-latest
     steps:
-      - name: Checkout project
-        uses: actions/checkout@v4
-      - name: Build Docker image
-        run: |
-          docker compose build
-      - name: Run test
-        run: |
-          docker compose run site pnpm build
+    - name: Get Docker files
+      uses: actions/checkout@v4
+    - name: Download website build artifact
+      uses: actions/download-artifact@v4
+      with:
+        name: build
+        path: build
+    - name: Restore docker image tar from cache
+      uses: actions/cache/restore@v4
+      with:
+        path: ${{ env.image_tar }}
+        key: image-${{ hashFiles('Dockerfile', 'compose.yml', 
'pnpm-lock.yaml') }}
+    - name: Load docker image
+      run: |
+        docker load --input="${{ env.image_tar }}"
+    - name: Curl website homepage
+      timeout-minutes: 5
+      working-directory: ${{ env.script_dir }}
+      run: |
+        ./curl.sh
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 042b0e55..0e435f3b 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -13,50 +13,48 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Build Ozone website v2 and commit it to a staging branch.
-# This will be picked up by configurations in .asf.yml to publish it to a 
staging domain.
-name: "auto-publish-website-v2"
+# Commits the website build to the asf-site-v2 branch, where ASF automation 
configured by the .asf.yaml file on that
+# branch will publish it to the specified domain.
+# The website build is read from an artifact and is not built in this workflow.
+
+name: publish
 
 on:
-  push:
-    branches:
-      # TODO update this to master when the new website is ready to be 
published.
-      - HDDS-9225-website-v2
+  workflow_call:
+
+concurrency:
+  group: publish-${{ github.sha }}
+  cancel-in-progress: ${{ github.event_name == 'push' }}
 
 jobs:
-  build:
+  publish-website:
     runs-on: ubuntu-latest
     steps:
-      # Check out the website source in the current working directory.
-      - name: "Checkout source branch ${{ github.ref_name }}"
-        uses: actions/checkout@v4
-        with:
-          path: 'src'
-      - name: "Build website"
-        working-directory: 'src'
-        # Website source is mounted as volume, so the build output ends up in 
./src/build outside of the container.
-        run: |
-          docker compose run site pnpm run build
-      - name: "Checkout publish branch"
-        uses: actions/checkout@v4
-        with:
-          path: 'publish'
-          # TODO update this to asf-site when the website is ready to be 
published.
-          ref: 'asf-site-v2'
-      - name: "Commit changes"
-        working-directory: 'publish'
-        run: |
-          # Delete previous build from the branch, but preserve files with 
necessary metadata.
-          mv README.md .asf.yaml .git /tmp
-          rm -rf $(ls -A)
-          mv /tmp/README.md /tmp/.asf.yaml /tmp/.git .
+    - name: Download website build artifact
+      uses: actions/download-artifact@v4
+      with:
+        name: build
+        path: build
+    - name: Checkout publish branch
+      uses: actions/checkout@v4
+      with:
+        path: publish
+        # Update this to asf-site when the website is ready to be published.
+        ref: asf-site-v2
+    - name: Commit changes
+      working-directory: publish
+      run: |
+        # Delete previous build from the branch, but preserve files with 
necessary metadata.
+        mv README.md .asf.yaml .git /tmp
+        rm -rf $(ls -A)
+        mv /tmp/README.md /tmp/.asf.yaml /tmp/.git .
 
-          # Commit new build to the branch.
-          cp -R ../src/build/. .
-          git config --global user.name 'Github Actions'
-          git config --global user.email '[email protected]'
-          git add .
-          git commit -a -m "[auto] Apply changes from $GITHUB_REF_NAME 
$GITHUB_SHA" || true
-          git push
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        # Commit new build to the branch.
+        cp -R ../build/. .
+        git config --global user.name 'Github Actions'
+        git config --global user.email '[email protected]'
+        git add .
+        git commit -a -m "[auto] Apply changes from $GITHUB_REF_NAME 
$GITHUB_SHA" || true
+        git push
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 275f1241..97388322 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -250,7 +250,7 @@ Docusaurus supports previewing the website locally. Below 
are various options to
 
 #### Option 1: Docker (Recommended)
 
-The project includes a `Dockerfile` and a `compose.yml` file to build and run 
the website in a containerized environment. This creates a docker image called 
`ozone-site-dev` with all the dependencies included, and uses it to run the 
[Docusaurus development 
server](https://docusaurus.io/docs/installation#running-the-development-server).
+The project includes a `Dockerfile` and a `compose.yml` file to build and run 
the website in a containerized environment. This creates a docker image called 
`ozone-site` with all the dependencies included, and uses it to run the 
[Docusaurus development 
server](https://docusaurus.io/docs/installation#running-the-development-server).
 
 1. Install [docker](https://docs.docker.com/engine/install/).
 
diff --git a/Dockerfile b/Dockerfile
index 955af001..4ce85b83 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -26,5 +26,6 @@ RUN corepack enable
 WORKDIR /ozone-site
 COPY package.json .
 COPY pnpm-lock.yaml .
-# Lockfile should not be changed when installing dependencies, hence freezing 
it.
-RUN pnpm install --frozen-lockfile
+# --frozen-lockfile: pnpm-lock.yaml is expected to match constraints in 
package.json. Fail if it does not.
+# --prod: Do not install dev dependencies. The image is only used for running 
the website.
+RUN pnpm install --prod --frozen-lockfile
diff --git a/compose.yml b/compose.yml
index 016d513f..c820e44d 100644
--- a/compose.yml
+++ b/compose.yml
@@ -18,7 +18,7 @@ version: "3"
 services:
   site:
     build: "."
-    image: "ozone-site-dev"
+    image: "ozone-site"
     ports:
       - 3000:3000
     volumes:


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to