Add GitHub Actions workflows for Docker image build and CI
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
name: Build and Push Docker Image
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- develop
|
||||
tags:
|
||||
- 'v*'
|
||||
- '[0-9]+.*'
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
IMAGE_NAME: christianlouis/leagueledger
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract Git Tag (if applicable)
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Extract metadata for tags
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
${{ env.IMAGE_NAME }}
|
||||
ghcr.io/${{ github.repository_owner }}/leagueledger
|
||||
|
||||
- name: Build and Push Docker Image with Provenance and SBOM
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
sbom: true
|
||||
provenance: mode=max
|
||||
tags: |
|
||||
${{ env.IMAGE_NAME }}:latest
|
||||
${{ env.IMAGE_NAME }}:${{ github.sha }}
|
||||
ghcr.io/${{ github.repository_owner }}/leageledgerp:latest
|
||||
ghcr.io/${{ github.repository_owner }}/leagueledger:${{ github.sha }}
|
||||
${{ startsWith(github.ref, 'refs/tags/') && format('{0}:{1}', env.IMAGE_NAME, env.VERSION) || '' }}
|
||||
${{ startsWith(github.ref, 'refs/tags/') && format('ghcr.io/{0}/leagueledger:{1}', github.repository_owner, env.VERSION) || '' }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
@@ -0,0 +1,35 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ vars.DOCKER_USER }}
|
||||
password: ${{ secrets.DOCKER_PAT }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver: cloud
|
||||
endpoint: "christianlouis/cklbuilder"
|
||||
install: true
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
tags: "${{ vars.DOCKER_USER }}/leagueledger:latest"
|
||||
outputs: ${{ github.event_name == 'pull_request' && 'type=cacheonly' || 'type=registry' }}
|
||||
provenance: mode=max
|
||||
sbom: true
|
||||
@@ -1,47 +0,0 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
app:
|
||||
image: leagueledger:latest
|
||||
deploy:
|
||||
replicas: 3
|
||||
update_config:
|
||||
parallelism: 2
|
||||
delay: 10s
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
networks:
|
||||
- traefik-public
|
||||
environment:
|
||||
- DATABASE_URL=postgresql://user:password@db:5432/leagueledger
|
||||
- SECRET_KEY=your-very-secret-session-key
|
||||
- TRAEFIK_ENTRYPOINT=http
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.leagueledger.rule=Host(`yourdomain.com`)"
|
||||
- "traefik.http.services.leagueledger.loadbalancer.server.port=8000"
|
||||
volumes:
|
||||
- ./app:/app
|
||||
ports:
|
||||
- "8000:8000"
|
||||
|
||||
db:
|
||||
image: postgres:13
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
networks:
|
||||
- traefik-public
|
||||
environment:
|
||||
POSTGRES_USER: user
|
||||
POSTGRES_PASSWORD: password
|
||||
POSTGRES_DB: leagueledger
|
||||
volumes:
|
||||
- db_data:/var/lib/postgresql/data
|
||||
|
||||
networks:
|
||||
traefik-public:
|
||||
external: true
|
||||
|
||||
volumes:
|
||||
db_data:
|
||||
Reference in New Issue
Block a user