diff --git a/.github/workflows/docker_deploy.yml b/.github/workflows/docker_deploy.yml index 9660de5..61b1651 100644 --- a/.github/workflows/docker_deploy.yml +++ b/.github/workflows/docker_deploy.yml @@ -11,34 +11,55 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: universalscientifictechnologies/dosportal/web + IMAGE_NAME_BASE: universalscientifictechnologies/dosportal jobs: - build-and-push-image: + build-and-push-images: runs-on: ubuntu-latest permissions: contents: read packages: write + strategy: + matrix: + include: + - component: backend + dockerfile: backend.Dockerfile + - component: frontend + dockerfile: frontend.Dockerfile steps: - name: Checkout repository uses: actions/checkout@v6 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v5 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Build and push Docker image + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BASE }}-${{ matrix.component }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha + + - name: Build and push Docker image (${{ matrix.component }}) uses: docker/build-push-action@v6 with: context: . - file: Dockerfile + file: ${{ matrix.dockerfile }} push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BASE }}-${{ matrix.component }}:buildcache + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BASE }}-${{ matrix.component }}:buildcache,mode=max diff --git a/.gitignore b/.gitignore index 4ce6e9c..d3224f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -./data/ - +data/ +static/ +staticfiles/ # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/backend.Dockerfile b/backend.Dockerfile index beaab30..db17b71 100644 --- a/backend.Dockerfile +++ b/backend.Dockerfile @@ -22,7 +22,11 @@ RUN apk add --no-cache \ WORKDIR /DOSPORTAL COPY requirements.txt /DOSPORTAL/ RUN pip install --no-cache-dir -r requirements.txt -#COPY . /DOSPORTAL/ -#COPY cari7a /usr/local/bin/cari7a + +COPY . /DOSPORTAL/ + +RUN python manage.py collectstatic --noinput --clear || true + +EXPOSE 8000 ENTRYPOINT ["python", "manage.py", "runserver", "0.0.0.0:8000"] diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..706cbbd --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,90 @@ +networks: + inet: + driver: bridge + ipam: + config: + - subnet: 10.5.0.0/16 + gateway: 10.5.0.1 + default: + driver: bridge + ipam: + driver: default + +services: + db_dosportal: + image: postgis/postgis + env_file: + - .env + volumes: + - ./data/dosportal/db_pg:/var/lib/postgresql/data + environment: + - POSTGRES_DB=${POSTGRES_DB:-dosportal} + - POSTGRES_USER=${POSTGRES_USER:-dosportal_user} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-dosportal_password} + networks: + inet: + ipv4_address: 10.5.0.5 + + backend: + image: ${BACKEND_IMAGE:-ghcr.io/universalscientifictechnologies/dosportal-backend:master} + env_file: + - .env + ports: + - "8100:8000" + depends_on: + - db_dosportal + - redis + - minio + networks: + inet: + ipv4_address: 10.5.0.6 + + worker: + image: ${BACKEND_IMAGE:-ghcr.io/universalscientifictechnologies/dosportal-backend:master} + entrypoint: ["python", "manage.py", "qcluster"] + env_file: + - .env + depends_on: + - backend + - db_dosportal + - redis + networks: + inet: + ipv4_address: 10.5.0.8 + + redis: + image: redis + depends_on: + - db_dosportal + networks: + inet: + ipv4_address: 10.5.0.7 + + minio: + image: minio/minio + env_file: + - .env + ports: + - "9000:9000" + - "9001:9001" + environment: + MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin} + MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minioadmin} + command: server /data --console-address ":9001" + volumes: + - ./data/minio:/data + networks: + inet: + ipv4_address: 10.5.0.9 + + frontend: + image: ${FRONTEND_IMAGE:-ghcr.io/universalscientifictechnologies/dosportal-frontend:master} + ports: + - "5173:5173" + environment: + - NODE_ENV=production + depends_on: + - backend + networks: + inet: + ipv4_address: 10.5.0.10