Skip to content
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
229 changes: 142 additions & 87 deletions .github/workflows/build-push-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,98 +3,153 @@ name: Build, Push and Commit Digest
on:
push:
branches:
- main
- develop
- main
- develop

jobs:
build_and_push:
runs-on: ubuntu-latest

env:
DEV_STAKING_API_URL: ${{ secrets.DEV_STAKING_API_URL || vars.DEV_STAKING_API_URL }}
PRO_STAKING_API_URL: ${{ secrets.PRO_STAKING_API_URL || vars.PRO_STAKING_API_URL }}
DEV_STAKING_API_DOC_JSON_URL: ${{ secrets.DEV_STAKING_API_DOC_JSON_URL || vars.DEV_STAKING_API_DOC_JSON_URL }}
PRO_STAKING_API_DOC_JSON_URL: ${{ secrets.PRO_STAKING_API_DOC_JSON_URL || vars.PRO_STAKING_API_DOC_JSON_URL }}
DEV_APP_URL: ${{ secrets.DEV_APP_URL || vars.DEV_APP_URL }}
PRO_APP_URL: ${{ secrets.PRO_APP_URL || vars.PRO_APP_URL }}
DEV_CHATWOOT_WEBSITE_TOKEN: ${{ secrets.DEV_CHATWOOT_WEBSITE_TOKEN }}
PRO_CHATWOOT_WEBSITE_TOKEN: ${{ secrets.PRO_CHATWOOT_WEBSITE_TOKEN }}
DEV_CHATWOOT_BASE_URL: ${{ secrets.DEV_CHATWOOT_BASE_URL || vars.DEV_CHATWOOT_BASE_URL }}
PRO_CHATWOOT_BASE_URL: ${{ secrets.PRO_CHATWOOT_BASE_URL || vars.PRO_CHATWOOT_BASE_URL }}
DEV_CHATWOOT_ENABLED: ${{ secrets.DEV_CHATWOOT_ENABLED || vars.DEV_CHATWOOT_ENABLED }}
PRO_CHATWOOT_ENABLED: ${{ secrets.PRO_CHATWOOT_ENABLED || vars.PRO_CHATWOOT_ENABLED }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get latest commit author and message
run: |
echo "COMMIT_AUTHOR=$(git log -1 --pretty=format:'%an')" >> $GITHUB_ENV
echo "COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s')" >> $GITHUB_ENV

- name: Extract branch name
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV

- name: Build and push Docker image
run: |
if [ "${{ env.BRANCH_NAME }}" = "develop" ]
then
docker build --build-arg STAKING_API_URL="https://dev-staking-api.stakely.io/docs" --build-arg STAKING_API_DOC_JSON_URL="https://dev-staking-api.stakely.io/docs-json" --build-arg APP_URL="https://dev-app.stakely.io" --build-arg CHATWOOT_WEBSITE_TOKEN="${{ secrets.DEV_CHATWOOT_WEBSITE_TOKEN }}" --build-arg CHATWOOT_BASE_URL="${{ vars.DEV_CHATWOOT_BASE_URL }}" --build-arg CHATWOOT_ENABLED="${{ vars.DEV_CHATWOOT_ENABLED }}" -t stakely/stakely-docs:${{ env.BRANCH_NAME }} .
elif [ "${{ env.BRANCH_NAME }}" = "main" ]
then
docker build --build-arg STAKING_API_URL="https://staking-api.stakely.io/docs" --build-arg STAKING_API_DOC_JSON_URL="https://staking-api.stakely.io/docs-json" --build-arg APP_URL="https://app.stakely.io" --build-arg CHATWOOT_WEBSITE_TOKEN="${{ secrets.PRO_CHATWOOT_WEBSITE_TOKEN }}" --build-arg CHATWOOT_BASE_URL="${{ vars.PRO_CHATWOOT_BASE_URL }}" --build-arg CHATWOOT_ENABLED="${{ vars.PRO_CHATWOOT_ENABLED }}" -t stakely/stakely-docs:${{ env.BRANCH_NAME }} .
fi
echo '${{ secrets.DOCKERHUB_PASSWORD }}' | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
docker push stakely/stakely-docs:${{ env.BRANCH_NAME }}

- name: Get image digest
id: get_digest
run: |
digest=$(docker inspect --format='{{index .RepoDigests 0}}' stakely/stakely-docs:${{ env.BRANCH_NAME }})
echo "IMAGE_DIGEST=$digest" >> $GITHUB_ENV

- name: Setup SSH
uses: MrSquaare/ssh-setup-action@v2.0.1
with:
host: github.com
private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Clone manifests repository
run: git clone git@github.com:Stakely/kubernetes-manifests.git

- name: Commit and push digest to second repository
run: |
cd kubernetes-manifests
echo "Image Digest: ${{ env.IMAGE_DIGEST }}"
# Replaces the image digest with the new one to trigger ArgoCD
if [ "${{ env.BRANCH_NAME }}" = "main" ]
then
yq e '.frontend.docs.image = "${{ env.IMAGE_DIGEST }}"' -i web/values.production.yaml
elif [ "${{ env.BRANCH_NAME }}" = "develop" ]
then
yq e '.frontend.docs.image = "${{ env.IMAGE_DIGEST }}"' -i web/values.development.yaml
fi
git config --global user.email "workflows@stakely.io"
git config --global user.name "Stakely Workflow"
git add -A
git commit -m "Update stakely-docs:${{ env.BRANCH_NAME }} image digest"
git push

- name: Send Discord notification if success
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: 'GitHub Actions'
avatar-url: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
embed-color: '3066993'
embed-description: |
Workflow _${{ github.workflow }}_ in repository https://github.com/${{ github.repository }}/tree/${{ env.BRANCH_NAME }} has completed and https://github.com/Stakely/kubernetes-manifests has been updated.
ArgoCD will deploy the changes in <3 min.
- **Commit**: _${{ env.COMMIT_MESSAGE }}_ by _${{ env.COMMIT_AUTHOR }}_
- **Branch**: ${{ github.ref_name }}
- **Status**: ${{ job.status }}

- name: Send Discord notification if error
if: failure()
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: 'GitHub Actions'
avatar-url: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
embed-color: '15158332'
embed-description: |
Error with the workflow _${{ github.workflow }}_ in https://github.com/${{ github.repository }}/actions.
Nothing will be deployed until this is fixed.
- **Commit**: _${{ env.COMMIT_MESSAGE }}_ by _${{ env.COMMIT_AUTHOR }}_
- **Branch**: ${{ github.ref_name }}
- **Status**: ${{ job.status }}
- name: Checkout code
uses: actions/checkout@v4

- name: Get latest commit author and message
run: |
echo "COMMIT_AUTHOR=$(git log -1 --pretty=format:'%an')" >> "$GITHUB_ENV"
echo "COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s')" >> "$GITHUB_ENV"

- name: Extract branch name
shell: bash
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> "$GITHUB_ENV"

- name: Build and push Docker image
shell: bash
env:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
run: |
set -euo pipefail

require_var() {
local name="$1" value="$2"
if [ -z "$value" ]; then
echo "ERROR: Required variable '$name' is not set or empty." >&2
exit 1
fi
}

if [ "$BRANCH_NAME" = "main" ]; then
STAKING_API_URL="${PRO_STAKING_API_URL}"
STAKING_API_DOC_JSON_URL="${PRO_STAKING_API_DOC_JSON_URL}"
APP_URL="${PRO_APP_URL}"
CHATWOOT_WEBSITE_TOKEN="${PRO_CHATWOOT_WEBSITE_TOKEN}"
CHATWOOT_BASE_URL="${PRO_CHATWOOT_BASE_URL}"
CHATWOOT_ENABLED="${PRO_CHATWOOT_ENABLED}"
else
STAKING_API_URL="${DEV_STAKING_API_URL}"
STAKING_API_DOC_JSON_URL="${DEV_STAKING_API_DOC_JSON_URL}"
APP_URL="${DEV_APP_URL}"
CHATWOOT_WEBSITE_TOKEN="${DEV_CHATWOOT_WEBSITE_TOKEN}"
CHATWOOT_BASE_URL="${DEV_CHATWOOT_BASE_URL}"
CHATWOOT_ENABLED="${DEV_CHATWOOT_ENABLED}"
fi

require_var "STAKING_API_URL" "$STAKING_API_URL"
require_var "STAKING_API_DOC_JSON_URL" "$STAKING_API_DOC_JSON_URL"
require_var "APP_URL" "$APP_URL"
require_var "CHATWOOT_WEBSITE_TOKEN" "$CHATWOOT_WEBSITE_TOKEN"
require_var "CHATWOOT_BASE_URL" "$CHATWOOT_BASE_URL"
require_var "CHATWOOT_ENABLED" "$CHATWOOT_ENABLED"

docker build \
--build-arg STAKING_API_URL="$STAKING_API_URL" \
--build-arg STAKING_API_DOC_JSON_URL="$STAKING_API_DOC_JSON_URL" \
--build-arg APP_URL="$APP_URL" \
--build-arg CHATWOOT_WEBSITE_TOKEN="$CHATWOOT_WEBSITE_TOKEN" \
--build-arg CHATWOOT_BASE_URL="$CHATWOOT_BASE_URL" \
--build-arg CHATWOOT_ENABLED="$CHATWOOT_ENABLED" \
-t "stakely/stakely-docs:${BRANCH_NAME}" .

echo '${{ secrets.DOCKERHUB_PASSWORD }}' | docker login -u '${{ secrets.DOCKERHUB_USERNAME }}' --password-stdin
docker push "stakely/stakely-docs:${BRANCH_NAME}"

- name: Get image digest
shell: bash
env:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
run: |
digest=$(docker inspect --format='{{index .RepoDigests 0}}' "stakely/stakely-docs:${BRANCH_NAME}")
echo "IMAGE_DIGEST=${digest}" >> "$GITHUB_ENV"

- name: Setup SSH
uses: MrSquaare/ssh-setup-action@v2.0.1
with:
host: github.com
private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Clone manifests repository
run: git clone git@github.com:Stakely/kubernetes-manifests.git

- name: Commit and push digest to manifests
shell: bash
env:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
IMAGE_DIGEST: ${{ env.IMAGE_DIGEST }}
run: |
set -euo pipefail
cd kubernetes-manifests
echo "Image Digest: ${IMAGE_DIGEST}"
if [ "$BRANCH_NAME" = "main" ]; then
VALUES_FILE=web/values.production.yaml
else
VALUES_FILE=web/values.development.yaml
fi
yq e ".frontend.docs.image = \"${IMAGE_DIGEST}\"" -i "$VALUES_FILE"
git config --global user.email "workflows@stakely.io"
git config --global user.name "Stakely Workflow"
git add -A
git commit -m "Update stakely-docs:${BRANCH_NAME} image digest"
git push

- name: Send Discord notification if success
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: 'GitHub Actions'
avatar-url: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
embed-color: '3066993'
embed-description: |
Workflow _${{ github.workflow }}_ in repository https://github.com/${{ github.repository }}/tree/${{ env.BRANCH_NAME }} has completed and https://github.com/Stakely/kubernetes-manifests has been updated.
ArgoCD will deploy the changes in <3 min.
- **Commit**: _${{ env.COMMIT_MESSAGE }}_ by _${{ env.COMMIT_AUTHOR }}_
- **Branch**: ${{ github.ref_name }}
- **Status**: ${{ job.status }}

- name: Send Discord notification if error
if: failure()
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: 'GitHub Actions'
avatar-url: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
embed-color: '15158332'
embed-description: |
Error with the workflow _${{ github.workflow }}_ in https://github.com/${{ github.repository }}/actions.
Nothing will be deployed until this is fixed.
- **Commit**: _${{ env.COMMIT_MESSAGE }}_ by _${{ env.COMMIT_AUTHOR }}_
- **Branch**: ${{ github.ref_name }}
- **Status**: ${{ job.status }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

.env
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Stage 1: Base image.
## Start with a base image containing NodeJS so we can build Docusaurus.
FROM node:24-slim as base
## Enable corepack.
# RUN corepack enable
## Enable corepack and activate pnpm.
RUN corepack enable && corepack prepare pnpm@11.1.2 --activate
## Set the working directory to `/opt/docusaurus`.
WORKDIR /opt/docusaurus

Expand Down Expand Up @@ -34,14 +34,14 @@ ENV CHATWOOT_BASE_URL=$CHATWOOT_BASE_URL
ARG CHATWOOT_ENABLED
ENV CHATWOOT_ENABLED=$CHATWOOT_ENABLED

RUN npm ci
RUN pnpm install --frozen-lockfile
## Build the static site.
RUN npm run build
RUN pnpm run build

# Serve with `docusaurus serve`.
FROM prod as serve
## Expose the port that Docusaurus will run on.
EXPOSE 3000
## Run the production server.
# CMD ["npm", "run", "serve", "--host 0.0.0.0", "--no-open"]
CMD ["sh", "-c", "STAKING_API_URL=$STAKING_API_URL STAKING_API_DOC_JSON_URL=$STAKING_API_DOC_JSON_URL npm run serve -- --host 0.0.0.0 --no-open"]
CMD ["node_modules/.bin/docusaurus", "serve", "--host", "0.0.0.0", "--no-open"]
Loading
Loading