Build and Deploy #25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy | |
on: | |
workflow_dispatch: | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- name: Cache node_modules | |
uses: actions/cache@v3 | |
with: | |
path: node_modules | |
key: node_modules-${{ hashFiles('package-lock.json') }} | |
- name: Install dependencies | |
run: npm install | |
- name: Run lint | |
run: npm run lint | |
test: | |
runs-on: ubuntu-latest | |
needs: [lint] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- name: Cache node_modules | |
uses: actions/cache@v3 | |
with: | |
path: node_modules | |
key: node_modules-${{ hashFiles('package-lock.json') }} | |
- name: Install dependencies | |
run: npm install | |
- name: Run Unit tests | |
run: npm run test | |
build: | |
runs-on: ubuntu-latest | |
needs: [test] | |
permissions: | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Generate calver tag | |
id: calver | |
run: | | |
echo "tag=$(date +%Y-%m)-${{ github.job }}" >> $GITHUB_OUTPUT | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker metadata | |
id: image_metadata | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/collinmurd/virtual-guillotine | |
tags: | | |
type=raw,value=${{ steps.calver.outputs.tag }} | |
type=raw,value=latest,enable={{is_default_branch}} | |
type=sha | |
- name: Docker build and push | |
uses: docker/build-push-action@v6 | |
with: | |
file: Dockerfile | |
tags: ${{ steps.image_metadata.outputs.tags }} | |
labels: ${{ steps.image_metadata.outputs.labels }} | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [build] | |
steps: | |
- name: Configure ssh key | |
env: | |
PRIVATE_KEY: ${{ secrets.GUILLOTINE_PRIVATE_KEY }} | |
run: | | |
echo "$PRIVATE_KEY" > id_rsa_guillotine | |
chmod 600 id_rsa_guillotine | |
- name: Docker Compose up | |
env: | |
HOST: "149.130.209.48" | |
run: | | |
ssh -i id_rsa_guillotine -o "StrictHostKeyChecking no" guillotine@$HOST " | |
curl -o pull_sleeper_players.sh https://raw.githubusercontent.com/collinmurd/virtual_guillotine/main/bin/pull_sleeper_players.sh | |
curl -o docker-compose.yaml https://raw.githubusercontent.com/collinmurd/virtual_guillotine/main/docker-compose.yaml | |
docker compose pull | |
docker compose up -d | |
" |