Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

46 updated use GitHub codespaces #103

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c150d74
.devcontainer
tyliec Jun 18, 2024
3bb9f7f
remove remoteUser override
tyliec Jun 18, 2024
c5dbb77
testing
tyliec Jun 18, 2024
185e2f2
test again
tyliec Jun 18, 2024
f7ef992
test
tyliec Jun 18, 2024
e7a1025
working basics
tyliec Jun 18, 2024
adbe771
base working + docker compose up functions locally
kobebuckley Jul 3, 2024
ccc3fcc
locally installed requirements through dockerfile - no error spinning…
kobebuckley Jul 3, 2024
00a2391
functional docker-compose up, next is testing the bash data/seed/init…
kobebuckley Jul 3, 2024
3caba9b
trying to fix port 8000, before it would run but kept closing
kobebuckley Jul 3, 2024
67d8c12
further testing needing for automation of server setup
kobebuckley Jul 3, 2024
c759734
copied entire root dir into docker for testing, 1 of the containers i…
kobebuckley Jul 9, 2024
6af8a79
still unhealthy with extra timer, will need more investigation
kobebuckley Jul 9, 2024
7c81652
updated health check to provide creds using ' -u '
kobebuckley Jul 22, 2024
a424f34
changes to compose to connect postgres and elastic to app 0 currently…
kobebuckley Jul 22, 2024
741048c
working on the #! | AttributeError: 'DatabaseOperations' object …
kobebuckley Jul 22, 2024
b8d50bf
changes to get the static files error and to ensure readyness for con…
kobebuckley Jul 22, 2024
ee54264
app trying to connect to DB, but unable to establish a connection
kobebuckley Jul 22, 2024
f799ff3
installed postgresql-client and curl onto dockerfile dependencies, re…
kobebuckley Jul 22, 2024
f51e839
added a password for base user to test out pings and other installs
kobebuckley Jul 22, 2024
1b2b47a
missing geo_db_type
kobebuckley Jul 22, 2024
30eb9b7
still issues with app_1 | AttributeError: 'DatabaseOperati…
kobebuckley Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
FROM mcr.microsoft.com/vscode/devcontainers/base:bullseye

# root access for the beginning of the script
USER root

# Install system-wide dependencies that cannot be done in a venv
# Install system-wide dependencies that cannot be done in a venv
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y --no-install-recommends \
libpoppler-cpp-dev \
python-is-python3 \
gdal-bin \
libgdal-dev \
imagemagick \
libmagickwand-dev \
python3-dev \
pkg-config \
build-essential \
python3-venv \
libproj-dev \
proj-data \
proj-bin \
libgeos-dev \
postgresql-client \
curl \
iputils-ping \
postgis \
postgresql-postgis \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Optional arguments
ARG INSTALL_ZSH="true"
ARG UPGRADE_PACKAGES="false"
ARG ENABLE_NONROOT_DOCKER="true"
ARG USE_MOBY="true"

# Enable new "BUILDKIT" mode for Docker CLI
ENV DOCKER_BUILDKIT=1

# Install needed packages and setup non-root user
ARG USERNAME=automatic
ARG USER_UID=1000
ARG USER_GID=$USER_UID

COPY .devcontainer/library-scripts/ /tmp/library-scripts/

RUN apt-get update \
&& /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
&& /bin/bash /tmp/library-scripts/docker-debian.sh "${ENABLE_NONROOT_DOCKER}" "/var/run/docker-host.sock" "/var/run/docker.sock" "${USERNAME}" \
&& groupadd -r baseuser && useradd -r -g baseuser baseuser \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts/

# Create directories for Elasticsearch and add necessary permissions
RUN mkdir -p /usr/share/elasticsearch /var/lib/elasticsearch /var/log/elasticsearch \
&& chown -R baseuser:baseuser /usr/share/elasticsearch /var/lib/elasticsearch /var/log/elasticsearch

# Create the static files directory
RUN mkdir -p /home/app/build

WORKDIR /home/app

# Copy your application code from the root directory
COPY . /home/app/

RUN chmod +x /home/app/data/seed/init_db.sh

# Create the virtual environment
RUN python3 -m venv /home/app/venv

# Debugging: Display directory structure to check if venv is created correctly
RUN ls -R /home/app

# Activate the virtual environment and install dependencies
RUN /bin/bash -c "source /home/app/venv/bin/activate && pip install --upgrade pip && pip install -r /home/app/requirements.txt"

# Debugging: Display Python and pip versions
RUN /bin/bash -c "source /home/app/venv/bin/activate && python --version && pip --version"

# Switch back to the baseuser
USER baseuser

# Setting the ENTRYPOINT to docker-init.sh will configure non-root access
# to the Docker socket. The script will also execute CMD as needed.
# ENTRYPOINT [ "/usr/local/share/docker-init.sh" ]

# Set the CMD to run your application directly
CMD ["/bin/bash", "-c", "\
while ! ping -c 1 db > /dev/null 2>&1; do \
echo 'Waiting for db...'; \
sleep 5; \
done; \
while ! ping -c 1 elasticsearch > /dev/null 2>&1; do \
echo 'Waiting for elasticsearch...'; \
sleep 5; \
done; \
source /home/app/venv/bin/activate; \
bash /home/app/data/seed/init_db.sh; \
python /home/app/manage.py migrate; \
python /home/app/manage.py runserver 0.0.0.0:8000; \
"]
36 changes: 36 additions & 0 deletions .devcontainer/codespaces-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
django==4.2.4
Markdown==3.4.3
celery==5.2.7
django-celery-email==3.0.0
django-taggit==4.0.0
pytz==2023.3
requests==2.31.0
django-floppyforms==1.9.0
python-magic==0.4.27
python-mimeparse==1.6.0
django-configurations==2.5.1
django-storages==1.13.2
dj-database-url==2.0.0
django-contrib-comments==2.2.0
unicodecsv==0.14.1
django-tinymce==3.6.1
python-docx==0.8.11
elasticsearch==8.11.1

-e git+https://github.com/codewithaloha/froide.git@main#egg=froide

lxml==5.2.1
channels==4.0.0
django-treebeard==4.4
django-leaflet==0.29.0
django-json-widget==1.1.1
django-celery-beat==2.5.0
django-mfa3==0.11.0
psycopg[binary]==3.1.18
psycopg-binary==3.1.18
-e git+https://github.com/okfde/django-filingcabinet.git@main#egg=django-filingcabinet
oauthlib==3.2.2
django-oauth-toolkit==1.7.1
django-fsm==2.8.1
websockets==11.0.3
bleach==6.0.0
19 changes: 19 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "UIPA DevBox",
"dockerComposeFile": "docker-compose.yml",
// "postStartCommand": "bash entrypoint.sh",
"service": "app",
"forwardPorts": [8000, 5432, 9200],
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-azuretools.vscode-docker"
],
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
}
}
},
"remoteUser": "vscode"
}
77 changes: 77 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
version: '3.8'

services:
app:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
ports:
- "127.0.0.1:8000:8000"
environment:
- DATABASE_URL=postgres://froide:froide@db:5432/froide
- ELASTICSEARCH_URL=http://elastic:froide@elasticsearch:9200
depends_on:
db:
condition: service_healthy
elasticsearch:
condition: service_healthy
networks:
- app-network

db:
image: postgis/postgis:14-3.1
volumes:
- pg-data:/var/lib/postgresql/data/
- ./postgresql.conf:/var/lib/postgresql/data/postgresql.conf
environment:
POSTGRES_USER: froide
POSTGRES_PASSWORD: froide
POSTGRES_DB: froide
ports:
- "127.0.0.1:5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U froide -d froide"]
interval: 10s
timeout: 5s
retries: 5
command: >
bash -c "
docker-entrypoint.sh postgres -c 'config_file=/var/lib/postgresql/data/postgresql.conf' &
sleep 10;
psql -U froide -d froide -c 'CREATE EXTENSION IF NOT EXISTS postgis;';
tail -f /dev/null
"
networks:
- app-network

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.0
user: root
volumes:
- es-data:/usr/share/elasticsearch/data
- es-logs:/var/log
environment:
- discovery.type=single-node
- xpack.security.enabled=true
- ELASTIC_PASSWORD=froide
- cluster.routing.allocation.disk.threshold_enabled=false
- cluster.routing.allocation.disk.watermark.low=3gb
- cluster.routing.allocation.disk.watermark.high=2gb
- cluster.routing.allocation.disk.watermark.flood_stage=1gb
ports:
- "127.0.0.1:9200:9200"
healthcheck:
test: ["CMD-SHELL", "curl -s -u elastic:froide http://localhost:9200/_cluster/health | grep -q '\"status\":\"green\"' || curl -s -u elastic:froide http://localhost:9200/_cluster/health | grep -q '\"status\":\"yellow\"'"]
interval: 30s
timeout: 10s
retries: 10
networks:
- app-network

volumes:
es-data: {}
es-logs: {}
pg-data: {}

networks:
app-network:
47 changes: 47 additions & 0 deletions .devcontainer/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

echo "Starting entrypoint script..."

# Navigate to the project root directory
echo "Changing directory to project root..."
cd ..

# Activate the virtual environment
echo "Activating virtual environment..."
source venv/bin/activate

# Run the initial setup script
echo "Running initial setup script..."
if bash data/seed/init_db.sh; then
echo "Initial setup script completed successfully."
else
echo "Initial setup script failed." >&2
exit 1
fi

# Check the Django project
echo "Checking Django project..."
if python manage.py check; then
echo "Django project check completed successfully."
else
echo "Django project check failed." >&2
exit 1
fi

# Apply database migrations
echo "Applying database migrations..."
if python manage.py migrate; then
echo "Database migrations applied successfully."
else
echo "Database migrations failed." >&2
exit 1
fi

# Start the development server
echo "Starting the development server..."
if python manage.py runserver 0.0.0.0:8000; then
echo "Development server started successfully."
else
echo "Failed to start the development server." >&2
exit 1
fi
18 changes: 18 additions & 0 deletions .devcontainer/init_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# init_db.sh - Initialize the database to the point before uploading public
# body data.
#

echo "Run initial migration..."
python manage.py migrate

echo
echo "Create and populate the search index..."
python manage.py search_index --populate

echo
echo "Load the seed data..."
python manage.py loaddata uipa_org/fixtures/*

echo
echo "Now you can start the dev web server."
Loading