Skip to content

Commit

Permalink
chore: update python to 3.12, django to 5.1 etc. deps
Browse files Browse the repository at this point in the history
  • Loading branch information
japsu committed Aug 11, 2024
1 parent 1941756 commit d475750
Show file tree
Hide file tree
Showing 11 changed files with 563 additions and 200 deletions.
133 changes: 97 additions & 36 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,155 @@ name: cicd
on:
push:
branches:
- development
- master
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: "1"
COMPOSE_DOCKER_CLI_BUILD: "1"
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- run: docker compose -f docker-compose.test.yml up --exit-code-from test

build:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
env:
SKAFFOLD_DEFAULT_REPO: ghcr.io/con2
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pairity/setup-cd-tools@30acb848f9ff747aff4810dac40c5cc0971f485d

- id: cache-bin
uses: actions/cache@v3
with:
skaffold: '1.20.0'
- uses: docker/login-action@v1
path: bin
key: ${{ runner.os }}-bin-2
- if: steps.cache-bin.outputs.cache-hit != 'true'
run: |
mkdir bin
curl -Lo bin/skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64
curl -Lo bin/kubectl https://dl.k8s.io/release/v1.22.0/bin/linux/amd64/kubectl
chmod +x bin/skaffold bin/kubectl
- run: echo "$PWD/bin" >> $GITHUB_PATH

- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_PASSWORD }}
- uses: docker/setup-buildx-action@v1
- uses: docker/setup-buildx-action@v3
- id: build
run: |
python3 -m pip install -U pip setuptools wheel
python3 -m pip install emskaffolden
emskaffolden -E staging -- build --file-output build.json
echo "::set-output name=build_json::$(base64 -w 0 < build.json)"
outputs:
build_json: ${{ steps.build.outputs.build_json }}
- uses: actions/upload-artifact@v3
with:
name: build-json
path: build.json

# TODO DRY
deploy_staging:
runs-on: self-hosted
needs: build
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }}
environment: staging
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: build-json
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pairity/setup-cd-tools@30acb848f9ff747aff4810dac40c5cc0971f485d

- id: cache-bin
uses: actions/cache@v3
with:
kubectl: '1.20.4'
skaffold: '1.20.0'
- uses: docker/setup-buildx-action@v1
path: bin
key: ${{ runner.os }}-bin-2
- if: steps.cache-bin.outputs.cache-hit != 'true'
run: |
mkdir bin
curl -Lo bin/skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64
curl -Lo bin/kubectl https://dl.k8s.io/release/v1.22.0/bin/linux/amd64/kubectl
chmod +x bin/skaffold bin/kubectl
- run: echo "$PWD/bin" >> $GITHUB_PATH

- run: |
python3 -m pip install -U pip setuptools wheel
python3 -m pip install emskaffolden
base64 -d <<< "${{ needs.build.outputs.build_json }}" > build.json
emskaffolden -E staging -- deploy -n conikuvat-staging -a build.json
deploy_conikuvat:
runs-on: self-hosted
needs: build
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
environment: production
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: build-json
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pairity/setup-cd-tools@30acb848f9ff747aff4810dac40c5cc0971f485d

- id: cache-bin
uses: actions/cache@v3
with:
kubectl: '1.20.4'
skaffold: '1.20.0'
- uses: docker/setup-buildx-action@v1
path: bin
key: ${{ runner.os }}-bin-2
- if: steps.cache-bin.outputs.cache-hit != 'true'
run: |
mkdir bin
curl -Lo bin/skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64
curl -Lo bin/kubectl https://dl.k8s.io/release/v1.22.0/bin/linux/amd64/kubectl
chmod +x bin/skaffold bin/kubectl
- run: echo "$PWD/bin" >> $GITHUB_PATH

- run: |
python3 -m pip install -U pip setuptools wheel
python3 -m pip install emskaffolden
base64 -d <<< "${{ needs.build.outputs.build_json }}" > build.json
emskaffolden -E production -- deploy -n conikuvat-production -a build.json
deploy_larppikuvat:
runs-on: self-hosted
needs: build
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
environment: production
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: build-json
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pairity/setup-cd-tools@30acb848f9ff747aff4810dac40c5cc0971f485d

- id: cache-bin
uses: actions/cache@v3
with:
kubectl: '1.20.4'
skaffold: '1.20.0'
- uses: docker/setup-buildx-action@v1
path: bin
key: ${{ runner.os }}-bin-2
- if: steps.cache-bin.outputs.cache-hit != 'true'
run: |
mkdir bin
curl -Lo bin/skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64
curl -Lo bin/kubectl https://dl.k8s.io/release/v1.22.0/bin/linux/amd64/kubectl
chmod +x bin/skaffold bin/kubectl
- run: echo "$PWD/bin" >> $GITHUB_PATH

- run: |
python3 -m pip install -U pip setuptools wheel
python3 -m pip install emskaffolden
base64 -d <<< "${{ needs.build.outputs.build_json }}" > build.json
emskaffolden -E larppikuvat -- deploy -n larppikuvat -a build.json
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11
FROM python:3.12
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/
RUN groupadd -g 1082 -r conikuvat && useradd -r -u 1082 -g conikuvat -G users conikuvat && \
Expand Down
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This is the REST API backend for Edegal. Technology choices include the following:

* Python (3.11+)
* Python (3.12+)
* Django (4.2+)
* PostgreSQL (15+)
* Redis
Expand Down
38 changes: 25 additions & 13 deletions backend/edegal/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,34 @@ class Meta:
model = Album


@admin.action(
description="Make not public, not visible"
)
def make_not_public_not_visible(modeladmin, request, queryset):
return queryset.update(is_public=False, is_visible=False)


make_not_public_not_visible.short_description = "Make not public, not visible"


@admin.action(
description="Make public but not visible"
)
def make_public_but_not_visible(modeladmin, request, queryset):
return queryset.update(is_public=True, is_visible=False)


make_public_but_not_visible.short_description = "Make public but not visible"


@admin.action(
description="Make public and visible"
)
def make_public_and_visible(modeladmin, request, queryset):
return queryset.update(is_public=True, is_visible=True)


make_public_and_visible.short_description = "Make public and visible"


@admin.register(Album)
class AlbumAdmin(MultiUploadAdmin):
model = Album
form = AlbumAdminForm
Expand Down Expand Up @@ -198,10 +205,12 @@ def get_queryset(self, request):
qs = super().get_queryset(request)
return qs.annotate(num_pictures=Count("pictures"))

@admin.display(
description="Pictures"
)
def admin_get_num_pictures(self, obj):
return obj.num_pictures

admin_get_num_pictures.short_description = "Pictures"


class MediaInline(admin.TabularInline):
Expand All @@ -214,6 +223,7 @@ class MediaInline(admin.TabularInline):
show_change_link = False


@admin.register(Picture)
class PictureAdmin(admin.ModelAdmin):
model = Picture
readonly_fields = ("path", "taken_at", "created_at", "updated_at", "created_by")
Expand All @@ -223,20 +233,25 @@ class PictureAdmin(admin.ModelAdmin):
inlines = (MediaInline,)


@admin.action(
description="Activate selected media specs"
)
def activate_media_specs(modeladmin, request, queryset):
queryset.update(active=True)


activate_media_specs.short_description = "Activate selected media specs"


@admin.action(
description="Deactivate selected media specs"
)
def deactivate_media_specs(modeladmin, request, queryset):
queryset.update(active=False)


deactivate_media_specs.short_description = "Deactivate selected media specs"


@admin.register(MediaSpec)
class MediaSpecAdmin(admin.ModelAdmin):
model = MediaSpec
list_display = ("role", "max_width", "max_height", "quality", "format", "active")
Expand Down Expand Up @@ -277,6 +292,7 @@ class Meta:
photographer_inlines.append(LarppikuvatPhotographerProfileInlineAdmin)


@admin.register(Photographer)
class PhotographerAdmin(admin.ModelAdmin):
model = Photographer
form = PhotographerAdminForm
Expand Down Expand Up @@ -308,6 +324,7 @@ class Meta:
model = Series


@admin.register(Series)
class SeriesAdmin(admin.ModelAdmin):
model = Series
form = SeriesAdminForm
Expand All @@ -321,6 +338,7 @@ def save_model(self, request, obj, form, change):
return super().save_model(request, obj, form, change)


@admin.register(TermsAndConditions)
class TermsAndConditionsAdmin(admin.ModelAdmin):
model = TermsAndConditions
list_display = ("admin_get_abridged_text", "url", "user", "is_public")
Expand All @@ -346,6 +364,7 @@ def has_delete_permission(self, request, obj):
return False


@admin.register(ImportJob)
class ImportJobAdmin(admin.ModelAdmin):
model = ImportJob
inlines = (ImportItemInline,)
Expand Down Expand Up @@ -374,13 +393,6 @@ def has_change_permission(self, request, obj=None):
return False


admin.site.register(Album, AlbumAdmin)
admin.site.register(MediaSpec, MediaSpecAdmin)
admin.site.register(Photographer, PhotographerAdmin)
admin.site.register(Picture, PictureAdmin)
admin.site.register(Series, SeriesAdmin)
admin.site.register(TermsAndConditions, TermsAndConditionsAdmin)
admin.site.register(ImportJob, ImportJobAdmin)

admin.site.site_header = "Edegal Admin"
admin.site.site_title = "Edegal Admin"
Expand Down
Loading

0 comments on commit d475750

Please sign in to comment.