Skip to content

Commit

Permalink
application startup fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nuwan-samarasinghe committed Sep 16, 2024
1 parent 2b0e25d commit f72b794
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 33 deletions.
53 changes: 43 additions & 10 deletions .github/workflows/pullpreview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,52 @@ jobs:
with:
environment: ${{ inputs.environment }}

paketo_build:
docker-build:
runs-on: ubuntu-latest
needs: [ setup ]
permissions:
packages: write
uses: communitiesuk/funding-service-design-workflows/.github/workflows/package.yml@main
with:
version_to_build: sha-${{ github.sha }}
owner: ${{ github.repository_owner }}
application: funding-service-design-fund-application-builder
assets_required: false
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: "Set version in env"
id: set-version
run: |
source version
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v4
with:
images: ${{env.IMAGE_REPO_PATH}}/${{env.IMAGE_NAME}}
tags: |
type=sha,format=long
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=${{env.VERSION}},enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=latest
type=ref,event=branch
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push docker image
uses: docker/build-push-action@v4
with:
context: .
tags: ${{ steps.metadata.outputs.tags}}
labels: ${{ steps.metadata.outputs.labels }}
push: true
file: ./Dockerfile.pullpreview
build-args: |
LAST_TAG='${{env.VERSION}}'
LAST_COMMIT='${{ github.sha }}'
deploy:
needs: [ setup, paketo_build ]
needs: [ setup, docker-build ]
permissions:
contents: read # to fetch code (actions/checkout)
deployments: write # to delete deployments
Expand Down
41 changes: 18 additions & 23 deletions Dockerfile.pullpreview
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
# Start with a Python base image
FROM python:3.10-slim
# Install PostgreSQL
RUN apt-get update && \
apt-get install -y postgresql postgresql-contrib
# Set environment variables for PostgreSQL
ENV POSTGRES_USER=postgres \
POSTGRES_PASSWORD=password \
POSTGRES_DB=fund_builder
# Expose the default PostgreSQL port
EXPOSE 5432
# Create a directory for the app
###############################################################################
#
# Fund Application Builder (FAB) Dev Image
#
###############################################################################

FROM python:3.10-bullseye as fab-dev
ARG USE_DEV_REQUIREMENTS

WORKDIR /app
# Copy application files

COPY requirements.txt requirements.txt
COPY requirements-dev.txt requirements-dev.txt

RUN python3 -m pip install --upgrade pip && pip install -r requirements-dev.txt;

COPY . .
# Install Python dependencies into a virtual environment
RUN pip install --upgrade pip && pip install -r requirements-dev.txt
# Configure PostgreSQL (set up user, database, etc.)
RUN service postgresql start && \
su - postgres -c "psql -c \"ALTER USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWORD}';\"" && \
su - postgres -c "psql -c \"CREATE DATABASE ${POSTGRES_DB};\"" && \
su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_DB} TO ${POSTGRES_USER};\""
# Expose Flask app port

EXPOSE 8080
# Start PostgreSQL and the Flask app using the virtual environment
CMD service postgresql start && /bin/bash -c "python -m flask db upgrade && python -m flask run --no-debugger --host 0.0.0.0 --port 8080"

CMD ["flask", "run", "--port", "8080", "--host", "0.0.0.0"]

0 comments on commit f72b794

Please sign in to comment.