52 lines
1.5 KiB
YAML
52 lines
1.5 KiB
YAML
name: Main
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
build-and-push-docker-image:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
node-version: [20.x]
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- name: Log into registry ${{ env.REGISTRY }}
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Setup Docker buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
- name: Extract Docker metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v4
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
- name: Build and Push Versioned Docker Image
|
|
id: build-and-push
|
|
uses: docker/build-push-action@v4
|
|
if: ${{ github.ref != 'refs/heads/main' }}
|
|
with:
|
|
context: .
|
|
push: ${{ !github.event.pull_request.head.repo.fork }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
- name: Build and Push Latest Docker Image
|
|
id: build-and-push-latest
|
|
uses: docker/build-push-action@v4
|
|
if: ${{ github.ref == 'refs/heads/main' }}
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
labels: ${{ steps.meta.outputs.labels }}
|