From e7ab1e433c3d678080101b33a3efb8de34638355 Mon Sep 17 00:00:00 2001 From: Nuwan Samarasinghe Date: Sat, 7 Sep 2024 14:46:06 +0100 Subject: [PATCH] adding pull preview --- .flaskenv | 2 +- .github/workflows/pullpreview.yml | 31 +++++++++++++++++++++++++++++++ Dockerfile.pullpreview | 26 ++++++++++++++++++++++++++ docker-compose.pullpreview.yml | 20 ++++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pullpreview.yml create mode 100644 Dockerfile.pullpreview create mode 100644 docker-compose.pullpreview.yml diff --git a/.flaskenv b/.flaskenv index 05e8e4a..5cd4b3a 100644 --- a/.flaskenv +++ b/.flaskenv @@ -1,3 +1,3 @@ -FLASK_APP=app.app.py +FLASK_APP=app.py FLASK_ENV=development FLASK_RUN_PORT=5000 diff --git a/.github/workflows/pullpreview.yml b/.github/workflows/pullpreview.yml new file mode 100644 index 0000000..9fcedd1 --- /dev/null +++ b/.github/workflows/pullpreview.yml @@ -0,0 +1,31 @@ +name: PullPreview +on: + pull_request: + types: [labeled, unlabeled, synchronize, closed, reopened] + +jobs: + deploy: + permissions: + contents: read # to fetch code (actions/checkout) + deployments: write # to delete deployments + pull-requests: write # to remove labels + statuses: write # to create commit status + id-token: write # This is required for AWS credentials + name: deploy + runs-on: ubuntu-latest + timeout-minutes: 30 + environment: ${{ inputs.environment || 'dev' }} + steps: + - name: configure aws credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/GithubCopilotDeploy + role-session-name: FUNDING_SERVICE_DESIGN_FUND_APPLICATION_BUILDER_PULLPREVIEW + aws-region: eu-west-2 + - uses: actions/checkout@v2 + - uses: pullpreview/action@v5.6.1 + with: + compose_files: docker-compose.pullpreview.yml + ports: 8080/tcp + default_port: 8080 + admins: gidsg \ No newline at end of file diff --git a/Dockerfile.pullpreview b/Dockerfile.pullpreview new file mode 100644 index 0000000..de49331 --- /dev/null +++ b/Dockerfile.pullpreview @@ -0,0 +1,26 @@ +# 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 +WORKDIR /app +# Copy application files +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 debugpy --listen 0.0.0.0:5601 -m flask run --no-debugger --host 0.0.0.0 --port 8080" \ No newline at end of file diff --git a/docker-compose.pullpreview.yml b/docker-compose.pullpreview.yml new file mode 100644 index 0000000..5e1a716 --- /dev/null +++ b/docker-compose.pullpreview.yml @@ -0,0 +1,20 @@ + +services: + fab: + hostname: fab + build: + context: ../funding-service-design-fund-application-builder + dockerfile: Dockerfile.pullpreview + volumes: [ + '../funding-service-design-fund-application-builder:/app', + '../funding-service-design-fund-application-builder/postgresql:/var/lib/postgresql/data', + ] + ports: + - 5432:5432 + - 8080:8080 + environment: + - FORM_RUNNER_INTERNAL_HOST=http://localhost:3009 + - FORM_RUNNER_EXTERNAL_HOST=http://localhost:3009 + - DATABASE_URL=postgresql://postgres:password@localhost:5432/fund_builder + - FLASK_DEBUG=0 + - FLASK_ENV=development \ No newline at end of file