Skip to content

v0.2.0

v0.2.0 #1

Workflow file for this run

name: Nitro CD
run-name: ${{ github.ref_name }}
on:
push:
tags:
- 'v*.*.*'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
REPO: ${{ github.repository }}
REGISTRY: ${{ vars.REGISTRY }}
USERNAME: ${{ vars.USERNAME }}
PORT: ${{ vars.PORT }}
NODE_ENV: production
NITRO_PRESET: ${{ vars.NITRO_PRESET }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
outputs:
image_name: ${{ steps.metadata.outputs.image_name }}
image_title: ${{ steps.metadata.outputs.image_title }}
buildtime: ${{ steps.metadata.outputs.buildtime }}
version: ${{ steps.metadata.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- 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
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.REPO }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=sha-,format=short
- name: Set tags as environment variable
id: metadata
run: |
echo "Setting metadata to env variables"
echo "image_name=${{ fromJSON(steps.meta.outputs.json).tags[0] }}" >> $GITHUB_OUTPUT
echo "image_title=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }}" >> $GITHUB_OUTPUT
echo "buildtime=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}" >> $GITHUB_OUTPUT
echo "version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" >> $GITHUB_OUTPUT
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.metadata.outputs.version }}
BUILD_TIME=${{ steps.metadata.outputs.buildtime }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.REPO }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: false
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy to VPS
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USERNAME }}
password: ${{ secrets.VPS_PASSWORD }}
script: |
# Pull new image
docker pull ${{ needs.build_web.outputs.image_name }}
# Stop the existing container
docker stop ${{ needs.build_web.outputs.image_title }} || true
docker rm ${{ needs.build_web.outputs.image_title }} || true
# Create and start new container
docker run --detach \
--name ${{ needs.build_web.outputs.image_title }} \
--restart unless-stopped \
--mount type=bind,source=$(pwd)/${{ needs.build_web.outputs.image_title }}/static,target=/app/static,readonly \
--env-file ~/${{ needs.build_web.outputs.image_title }}/.env.prod \
-p ${{ env.PORT }}:3000 \
${{ needs.build_web.outputs.image_name }}
# Clean up unused images
docker image prune -f