93 lines
2.0 KiB
YAML
93 lines
2.0 KiB
YAML
name: Build, Test & Publish
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build:
|
|
name: Build
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
|
|
- name: Install dependencies
|
|
run: npm install
|
|
|
|
- name: Build
|
|
run: npm run build
|
|
|
|
publish:
|
|
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
name: Build and Publish Container Image
|
|
runs-on: ubuntu-latest
|
|
|
|
needs:
|
|
- build
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Setup Docker Metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v4
|
|
with:
|
|
images: liamsgit.dev/LiamPietralla/code-snippets
|
|
tags: |
|
|
type=raw,value=latest
|
|
type=sha,value=${{ github.sha }}
|
|
|
|
- name: Login to Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: liamsgit.dev
|
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Build and Push Docker Image to Registry
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
deploy:
|
|
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
name: Deploy to Infrastructure
|
|
runs-on: ubuntu-latest
|
|
|
|
needs:
|
|
- publish
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Write GitHub SSH Key to File
|
|
env:
|
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
run: |
|
|
echo "$SSH_PRIVATE_KEY" > private.key
|
|
sudo chmod 400 private.key
|
|
|
|
- name: Setup Nomad
|
|
uses: hashicorp/setup-nomad@main
|
|
with:
|
|
nomad_version: '1.10.5'
|
|
|
|
- name: Deploy Job to Nomad
|
|
run: |
|
|
nomad job run -var="version=${{ github.sha }}" infra/nomad/code-snippets.nomad.hcl
|
|
env:
|
|
NOMAD_ADDR: ${{ vars.NOMAD_ADDR }}
|