Skip to content

Commit

Permalink
added blog post on automatic deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
leon3s committed Nov 23, 2024
1 parent 95bd86e commit 82f4932
Show file tree
Hide file tree
Showing 9 changed files with 514 additions and 48 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build and publish docker image

on:
push:
branches:
- master

jobs:
deploy:
name: Build and publish docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

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

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract version from package.json
id: extract_version
run: |
version=$(jq -r '.version' package.json)
echo "PACKAGE_VERSION=$version" >> $GITHUB_ENV
- name: Check if version already exists
id: check_version
run: |
VERSION=${{ env.PACKAGE_VERSION }}
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/my-image
if docker manifest inspect $IMAGE_NAME:$VERSION > /dev/null 2>&1; then
echo "Version $VERSION already exists."
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/documentation:latest
ghcr.io/${{ github.repository_owner }}/documentation:${{ env.PACKAGE_VERSION }}
25 changes: 25 additions & 0 deletions .github/workflows/build_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build website

on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches: [main]

jobs:
test-deploy:
name: Build check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 22.x
cache: npm

- name: Install dependencies
run: npm ci

- name: Test build website
run: npm run build
32 changes: 32 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Deploy

on:
workflow_run:
workflows: ["Build and publish Docker image"]
types:
- completed

jobs:
deploy:
runs-on: ubuntu-latest

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

- name: Install nanocl cli
run: |
wget https://github.com/next-hat/nanocl/releases/download/nanocl-0.16.1-nightly/nanocl_0.16.1_amd64.deb
sudo dpkg -i nanocl_0.16.1_amd64.deb
rm nanocl_0.16.1_amd64.deb
- name: Deploy to production
run: |
VERSION=$(jq -r '.version' package.json)
nanocl version
echo $VERSION
nanocl state apply -ys Statefile.yml -- --version $VERSION
env:
HOST: ${{ secrets.NANOCL_HOST }}
CERT: ${{ secrets.NANOCL_CERT }}
CERT_KEY: ${{ secrets.NANOCL_CERT_KEY }}
46 changes: 0 additions & 46 deletions .github/workflows/publish.yml

This file was deleted.

31 changes: 31 additions & 0 deletions Statefile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ApiVersion: v0.16

Args:
- Name: version
Kind: String

Cargoes:
- Name: nh-doc
Container:
Image: ghcr.io/next-hat/documentation:${{ Args.version }}

Resources:
- Name: http.docs.next-hat.com
Kind: ncproxy.io/rule
Data:
Rules:
- Domain: docs.next-hat.com
Network: Public
Ssl: cert.next-hat.com
Locations:
- Path: /
Target:
Key: nh-doc.global.c
Port: 80
- Domain: docs.next-hat.com
Network: Public
Locations:
- Path: /
Target:
Url: https://docs.next-hat.com
Redirect: Temporary
Loading

0 comments on commit 82f4932

Please sign in to comment.