forked from enviPath/enviPy
[Chore] Build Docker Images on pushes to develop, main (#444)
Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#444
This commit is contained in:
64
.gitea/workflows/build-image.yaml
Normal file
64
.gitea/workflows/build-image.yaml
Normal file
@ -0,0 +1,64 @@
|
||||
name: Build Docker Image
|
||||
|
||||
# Trigger manually or when a PR to main is completed.
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- develop
|
||||
types:
|
||||
- closed
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Fetch the repository content for the Docker build context.
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Enable Buildx for BuildKit features (incl. SSH mount support).
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
# Authenticate against the container registry before pushing images.
|
||||
- name: Log in to container registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.envipath.com
|
||||
username: ${{ secrets.CI_REGISTRY_USER }}
|
||||
password: ${{ secrets.CI_REGISTRY_PASSWORD }}
|
||||
|
||||
# Generate image tags/labels:
|
||||
# - main branch gets stable "envipy" and "latest" tags
|
||||
# - every build gets an increasing build number tag
|
||||
# - branch-prefixed commit SHA tag remains for traceability
|
||||
- name: Extract metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: git.envipath.com/envipath/envipy
|
||||
tags: |
|
||||
type=raw,value=envipy,enable=${{ github.ref_name == 'main' }}
|
||||
type=raw,value=latest,enable=${{ github.ref_name == 'main' }}
|
||||
type=raw,value=build-${{ github.run_number }}
|
||||
type=sha,prefix={{branch}}-
|
||||
|
||||
# Load SSH key so Docker can pull private git+ssh dependencies during build.
|
||||
- name: Setup SSH for private git dependencies
|
||||
uses: webfactory/ssh-agent@v0.9.0
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.ENVIPY_CI_PRIVATE_KEY }}
|
||||
|
||||
# Build and push the production image; forward SSH agent without registry cache reuse.
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
push: true
|
||||
ssh: default
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
@ -58,6 +58,10 @@ COPY tests tests
|
||||
COPY utilities utilities
|
||||
COPY manage.py .
|
||||
|
||||
# Used to run migrations etc
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
# Install frontend deps
|
||||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
||||
|
||||
@ -100,4 +104,5 @@ USER django
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["gunicorn", "envipath.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3"]
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
CMD ["gunicorn", "envipath.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "8"]
|
||||
|
||||
9
entrypoint.sh
Normal file
9
entrypoint.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
if [ "${SKIP_DJANGO_SETUP:-false}" != "true" ]; then
|
||||
python manage.py migrate --no-input
|
||||
python manage.py collectstatic --no-input
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
Reference in New Issue
Block a user