From 243cf6e86202a97d38911141b759e14f60568b5c Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Pelayo Date: Sun, 3 Nov 2024 21:03:39 +0100 Subject: [PATCH] Website devspace --- .devfile.yaml | 28 +++++++++ .devfile/Containerfile | 19 ++++++ .devfile/install_hugo.sh | 27 +++++++++ .github/workflows/build-and-push.yaml | 85 +++++++++++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 .devfile.yaml create mode 100644 .devfile/Containerfile create mode 100755 .devfile/install_hugo.sh create mode 100644 .github/workflows/build-and-push.yaml diff --git a/.devfile.yaml b/.devfile.yaml new file mode 100644 index 0000000..6b274af --- /dev/null +++ b/.devfile.yaml @@ -0,0 +1,28 @@ +schemaVersion: 2.3.0 +metadata: + name: jumpstarter-website-dev + icon: https://jumpstarter.dev/jumpstarter.svg + tags: + - hugo + - website + language: Python +projects: + - name: jumpstarter + git: + remotes: + origin: https://github.com/jumpstarter-dev/website.git +components: + - name: runtime + container: + image: quay.io/jumpstarter-dev/jumpstarter-website-devspace:latest + endpoints: + - name: website + targetPort: 1313 + protocol: http + mountSources: true + +commands: + - id: serve-website + exec: + component: runtime + commandLine: hugo serve diff --git a/.devfile/Containerfile b/.devfile/Containerfile new file mode 100644 index 0000000..94230a4 --- /dev/null +++ b/.devfile/Containerfile @@ -0,0 +1,19 @@ +FROM quay.io/devfile/base-developer-image:ubi9-latest +LABEL maintainer="jumpstarter.dev" + +LABEL name="devfile/udi9/jumpstarter-website" + +#labels for container catalog +LABEL summary="devfile jumpstarter website developer image" +LABEL description="Devspaces image for maintaining the website" +LABEL io.k8s.display-name="jumpstarter-website-developer" + + +# Install required packages +USER root +RUN dnf install -y nodejs npm git golang jq && dnf clean all +COPY .devfile/install_hugo.sh /tmp/install_hugo.sh +RUN /tmp/install_hugo.sh + +USER 10001 + diff --git a/.devfile/install_hugo.sh b/.devfile/install_hugo.sh new file mode 100755 index 0000000..7053e74 --- /dev/null +++ b/.devfile/install_hugo.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +set -ex + +ARCH=$(uname -m) + +case $ARCH in + x86_64) + ;; + aarch64) + ARCH="arm64" + ;; + *) + echo "Unsupported architecture: $ARCH" + exit 1 + ;; +esac + +URL=$(curl https://api.github.com/repos/gohugoio/hugo/releases/latest -s | \ + jq -r ".assets[] | select(.name | test(\"linux\")) | .browser_download_url" | \ + grep .tar.gz | \ + grep -v extended | \ + grep "${ARCH}") + +echo $URL +curl -L $URL | tar xvfz - -C /usr/bin hugo + diff --git a/.github/workflows/build-and-push.yaml b/.github/workflows/build-and-push.yaml new file mode 100644 index 0000000..6ef2d66 --- /dev/null +++ b/.github/workflows/build-and-push.yaml @@ -0,0 +1,85 @@ +name: Build and push container image +on: + workflow_dispatch: + push: + merge_group: + +env: + PUSH: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }} + REGISTRY: quay.io + QUAY_ORG: quay.io/jumpstarter-dev + +jobs: + build-and-push-image: + strategy: + matrix: + image: + - jumpstarter-dev/jumpstarter-website-devspace .devfile/Containerfile + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + attestations: write + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get image name and container file + run: | + IMAGE="${{ matrix.image }}" + IMAGE_NAME=$(echo $IMAGE | awk '{print $1}') + CONTAINERFILE=$(echo $IMAGE | awk '{print $2}') + echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV + echo "IMAGE_NAME=${IMAGE_NAME}" + echo "CONTAINERFILE=${CONTAINERFILE}" >> $GITHUB_ENV + echo "CONTAINERFILE=${CONTAINERFILE}" + + - name: Get version + run: | + VERSION=$(git describe --tags) + VERSION=${VERSION#v} # remove the leading v prefix for version + echo "VERSION=${VERSION}" >> $GITHUB_ENV + echo "VERSION=${VERSION}" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + if: ${{ env.PUSH == 'true' }} + with: + registry: ${{ env.REGISTRY }} + username: jumpstarter-dev+jumpstarter_ci + password: ${{ secrets.QUAY_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@v6 + with: + context: . + file: ${{ env.CONTAINERFILE }} + push: ${{ env.PUSH }} + tags: ${{ steps.meta.outputs.tags }},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + if: ${{ env.PUSH == 'true' }} + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: ${{ env.PUSH }} \ No newline at end of file