mirror of
https://github.com/p-stream/backend.git
synced 2026-04-14 14:20:21 +00:00
67 lines
1.8 KiB
YAML
67 lines
1.8 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
tags:
|
|
- 'v*'
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v6.0.1
|
|
|
|
- name: Get version from package.json
|
|
id: package-version
|
|
run: |
|
|
VERSION=$(node -p "require('./package.json').version")
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3.12.0
|
|
|
|
- name: Log in to Container Registry
|
|
uses: docker/login-action@v3.6.0
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v5.10.0
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
# Set latest tag for master branch
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
# Use version from package.json
|
|
type=raw,value=${{ steps.package-version.outputs.version }}
|
|
# Use short SHA
|
|
type=sha,prefix=
|
|
# Use git tag if present
|
|
type=ref,event=tag
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v6.18.0
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
platforms: linux/amd64,linux/arm64
|
|
build-args: |
|
|
DATABASE_URL=postgresql://user:password@localhost:5432/db
|