Skip to content
Merged

Dev #100

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
changelog:
categories:
- title: 🏕 Features
labels:
- '*'
exclude:
labels:
- dependencies
- title: 👒 Dependencies
labels:
- dependencies
Original file line number Diff line number Diff line change
@@ -1,53 +1,64 @@
name: Build & Publish Docker Image
name: Build & Deploy to PROD

on:
release:
types: [published]
branches: [main]

workflow_call:
inputs:
tag_name:
description: Docker image tag / Release tag
required: true
type: string
target_commitish:
description: Branch to build from
required: true
type: string

jobs:
deploy:
if: github.event.release.target_commitish == 'main'
name: Build & Deploy spacedf-backend Docker Image
if: ${{ inputs.target_commitish == 'main' || github.event.release.target_commitish == 'main' }}
name: Build & Deploy
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

env:
RELEASE_TAG: ${{ inputs.tag_name || github.event.release.tag_name }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
ref: ${{ env.RELEASE_TAG }}

# Enable multi-arch
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

# Enable buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Login to GHCR
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Generate Docker metadata
- name: Docker metadata
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=${{ github.event.release.tag_name }}
type=semver,pattern={{major}}.{{minor}},value=${{ github.event.release.tag_name }}
type=semver,pattern={{major}},value=${{ github.event.release.tag_name }}
type=semver,pattern={{version}},value=${{ env.RELEASE_TAG }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.RELEASE_TAG }}
type=semver,pattern={{major}},value=${{ env.RELEASE_TAG }}

# Build & Push image
- name: Build & Push Docker image
uses: docker/build-push-action@v5
with:
Expand All @@ -57,5 +68,4 @@ jobs:
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
secrets: |
github_token=${{ secrets.GH_PAT }}
secrets: github_token=${{ secrets.GH_PAT }}
32 changes: 32 additions & 0 deletions .github/workflows/cd-promote-stable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Promote Docker Image to Stable

on:
workflow_dispatch:
inputs:
version:
description: "Docker image version (ex: 0.0.1)"
required: true

jobs:
promote:
runs-on: ubuntu-latest

permissions:
packages: write

steps:
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Promote version to stable
run: |
IMAGE=ghcr.io/${{ github.repository }}
VERSION=${{ inputs.version }}

docker buildx imagetools create \
-t $IMAGE:stable \
$IMAGE:$VERSION
33 changes: 33 additions & 0 deletions .github/workflows/dispatch-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Dispatch Release & Deploy to PROD
on:
repository_dispatch:
types:
- release-auth-service

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Client payload
run: |
cat <<'EOF'
${{ toJson(github.event.client_payload) }}
EOF

- name: Release
if: ${{ github.event.client_payload.release_target_commitish == 'main' }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.client_payload.release_tag }}
generate_release_notes: true
target_commitish: 'main'

deploy-prod:
uses: ./.github/workflows/cd-prod.yml
needs: [create-release]
with:
tag_name: ${{ github.event.client_payload.release_tag }}
target_commitish: ${{ github.event.client_payload.release_target_commitish }}
9 changes: 8 additions & 1 deletion auth_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import importlib
import os
from datetime import timedelta
from pathlib import Path

# Basic settings
SERVICE_NAME = "auth"
BASE_DIR = Path(__file__).resolve().parent.parent
COMMON_UTILS_DIR = Path(__file__).resolve().parent.parent.parent / "django-common-utils"

spec = importlib.util.find_spec("common")
if spec and spec.submodule_search_locations:
COMMON_UTILS_DIR = Path(list(spec.submodule_search_locations)[0]).parent
else:
raise ImportError

SECRET_KEY = os.getenv(
"SECRET_KEY", "django-insecure-*$0b8ibx7uzk45cm+fxw7*jj(yzi2ye!l4+!dnyxa-u-nbuz=q"
) # noqa
Expand Down
2 changes: 2 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/ash

python manage.py collectstatic --noinput

echo "Apply database migrations"
python manage.py migrate_schemas --shared
python manage.py migrate
Expand Down