Skip to content

add: create docker-compose.yml for server, browser, and postgres serv… #7

add: create docker-compose.yml for server, browser, and postgres serv…

add: create docker-compose.yml for server, browser, and postgres serv… #7

name: build-publish-image
on:
push:
branches: ['main', 'development']
paths:
- 'apps/**'
- 'packages/**'
- 'package.json'
- 'pnpm-lock.yaml'
- 'pnpm-workspace.yaml'
- 'tsconfig.json'
- 'turbo.json'
- 'docker-compose*.yml'
- '.github/workflows/build-publish-image.yml'
env:
REGISTRY: ghcr.io
IMAGE_PREFIX: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
strategy:
matrix:
app: [server, browser]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for git commands
- name: Determine environment
id: env
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "ENVIRONMENT=production" >> $GITHUB_OUTPUT
else
echo "ENVIRONMENT=development" >> $GITHUB_OUTPUT
fi
- name: Generate version
id: version
run: |
# Major: Years since 2024 (0, 1, 2...)
MAJOR=$(($(date +%Y) - 2024))
# Minor: Month (1-12)
MINOR=$(date +%m)
# Patch: Day of month (1-31)
PATCH=$(date +%d)
# Create version string
VERSION="${MAJOR}.${MINOR}.${PATCH}"
# Get short SHA
SHA=$(git rev-parse --short HEAD)
# Full version with SHA
FULL_VERSION="${VERSION}-${SHA}"
# Date for tagging
DATE=$(date +%Y%m%d)
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "FULL_VERSION=${FULL_VERSION}" >> $GITHUB_OUTPUT
echo "DATE=${DATE}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Metadata action
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}-${{ matrix.app}}
tags: |
type=raw,value=latest
type=raw,value=${{ steps.version.outputs.FULL_VERSION }}
type=raw,value=${{ steps.version.outputs.DATE }}
flavor: |
latest=${{ steps.env.outputs.ENVIRONMENT == 'production' }}
prefix=${{ steps.env.outputs.ENVIRONMENT == 'development' && 'development-' || '' }}
# For PR: Just build to verify it works without pushing
- name: Build only (PR check)
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09
with:
context: .
file: ./apps/${{ matrix.app }}/Dockerfile
target: production
push: false
build-args: |
VERSION=${{ steps.version.outputs.VERSION }}
ENVIRONMENT=${{ steps.env.outputs.ENVIRONMENT }}
- name: Build and push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09
with:
context: .
file: ./apps/${{ matrix.app }}/Dockerfile
target: production
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.version.outputs.VERSION }}
ENVIRONMENT=${{ steps.env.outputs.ENVIRONMENT }}
create-release:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate version
id: version
run: |
# Major: Years since 2024 (0, 1, 2...)
MAJOR=$(($(date +%Y) - 2024))
# Minor: Month (1-12)
MINOR=$(date +%m)
# Patch: Day of month (1-31)
PATCH=$(date +%d)
# Create version string
VERSION="${MAJOR}.${MINOR}.${PATCH}"
# Get short SHA
SHA=$(git rev-parse --short HEAD)
# Full version with SHA
FULL_VERSION="${VERSION}-${SHA}"
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "FULL_VERSION=${FULL_VERSION}" >> $GITHUB_OUTPUT
- name: Generate changelog
id: changelog
run: |
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges)
else
COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges)
fi
# Create changelog
CHANGELOG="## Docker Images
- \`ghcr.io/${{ github.repository }}-server:${{ steps.version.outputs.FULL_VERSION }}\`
- \`ghcr.io/${{ github.repository }}-browser:${{ steps.version.outputs.FULL_VERSION }}\`
## Changes
${COMMITS}
## Installation
\`\`\`bash
# Pull the latest images
docker pull ghcr.io/${{ github.repository }}-server:${{ steps.version.outputs.FULL_VERSION }}
docker pull ghcr.io/${{ github.repository }}-browser:${{ steps.version.outputs.FULL_VERSION }}
# Or use docker-compose with the release assets
wget https://github.com/${{ github.repository }}/releases/download/v${{ steps.version.outputs.FULL_VERSION }}/docker-compose.yml
docker-compose up -d
\`\`\`"
# Save changelog to file and output
echo "$CHANGELOG" > changelog.md
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.version.outputs.FULL_VERSION }}
name: ${{ steps.version.outputs.FULL_VERSION }}
body: ${{ steps.changelog.outputs.CHANGELOG }}
files: |
docker-compose-release.yml
docker-compose.yml
generate_release_notes: false