Merge pull request #46 from prose-im/master #48
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
on: | |
push: | |
branches: | |
- production | |
name: Build and Deploy | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
revision: ${{ steps.current_revision.outputs.short }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
lfs: true | |
- name: Install NodeJS | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
- name: Verify versions | |
run: node --version && npm --version && node -p process.versions.v8 | |
- name: Cache build context | |
id: cache-node | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.npm | |
.chappe | |
node_modules | |
key: ${{ runner.os }}-node | |
- name: Get current revision | |
id: current_revision | |
uses: prompt/actions-commit-hash@v3 | |
- name: Install dependencies | |
run: npm install --no-audit | |
- name: Build docs | |
run: npm run build production | |
- name: Archive build files | |
run: tar -zcvf ./build-${{ steps.current_revision.outputs.short }}.tar.gz build/ | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ steps.current_revision.outputs.short }} Build | |
path: ./build-${{ steps.current_revision.outputs.short }}.tar.gz | |
retention-days: 7 | |
ship: | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
env/nginx/ | |
Dockerfile | |
- name: Acquire Docker image metadata | |
id: metadata | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=ref,event=tag | |
type=raw,value=${{ needs.build.outputs.revision }} | |
type=raw,value=latest | |
- name: Log in to the container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Download build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ needs.build.outputs.revision }} Build | |
- name: Extract build artifacts | |
run: tar -xzvf ./build-${{ needs.build.outputs.revision }}.tar.gz | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
tags: ${{ steps.metadata.outputs.tags }} | |
labels: ${{ steps.metadata.outputs.labels }} | |
push: true | |
deploy: | |
needs: [build, ship] | |
environment: docs.prose.org | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install Nomad | |
uses: hashicorp/[email protected] | |
- name: Request deployment to Nomad | |
env: | |
NOMAD_ADDR: ${{ vars.NOMAD_ADDR }} | |
NOMAD_TOKEN: ${{ secrets.NOMAD_TOKEN }} | |
NOMAD_HTTP_AUTH: ${{ secrets.NOMAD_HTTP_AUTH }} | |
run: | | |
nomad var put -force nomad/jobs/prose-docs IMAGE_TAG=${{ needs.build.outputs.revision }} |