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

Add SQL-based migration script, with migration dir #878

Merged
merged 13 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
4 changes: 2 additions & 2 deletions docker-compose.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ services:
- fmtm_tiles:/opt/tiles
depends_on:
- fmtm-db
- migrations
- traefik
env_file:
- .env
Expand All @@ -109,13 +110,12 @@ services:
image: "ghcr.io/hotosm/fmtm/backend:${API_VERSION}-${GIT_BRANCH}"
container_name: fmtm_migrations
depends_on:
- api
- fmtm-db
env_file:
- .env
networks:
- fmtm-net
entrypoint: ["/migrate-entrypoint.sh"]
command: ["alembic", "upgrade", "head"]
restart: "on-failure:3"

ui:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.noodk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ services:
- ./src/backend/app:/opt/app
depends_on:
- fmtm-db
- migrations
env_file:
- .env
ports:
Expand All @@ -71,13 +72,12 @@ services:
image: "ghcr.io/hotosm/fmtm/backend:${API_VERSION}-${GIT_BRANCH}"
container_name: fmtm_migrations
depends_on:
- api
- fmtm-db
env_file:
- .env
networks:
- fmtm-net
entrypoint: ["/migrate-entrypoint.sh"]
command: ["alembic", "upgrade", "head"]
restart: "on-failure:3"

ui:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ services:
# - ../osm-fieldwork/osm_fieldwork:/home/appuser/.local/lib/python3.10/site-packages/osm_fieldwork
depends_on:
- fmtm-db
- migrations
- central-proxy
env_file:
- .env
Expand All @@ -78,13 +79,12 @@ services:
image: "ghcr.io/hotosm/fmtm/backend:debug"
container_name: fmtm_migrations
depends_on:
- api
- fmtm-db
env_file:
- .env
networks:
- fmtm-dev
entrypoint: ["/migrate-entrypoint.sh"]
command: ["alembic", "upgrade", "head"]
restart: "on-failure:3"

ui:
Expand Down
1 change: 0 additions & 1 deletion src/backend/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
!pyproject.toml
!pdm.lock
!migrations
!alembic.ini
24 changes: 12 additions & 12 deletions src/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ WORKDIR /opt
# Add app code
COPY app/ /opt/app/
COPY migrations/ /opt/migrations/
COPY alembic.ini /opt/
# Add non-root user, permissions
RUN useradd -r -u 1001 -m -c "hotosm account" -d /home/appuser -s /bin/false appuser \
&& mkdir -p /opt/logs /opt/tiles \
Expand Down Expand Up @@ -150,23 +149,24 @@ USER appuser
FROM runtime as ci
# Run all ci as root
USER root
ENV PATH="/root/.local/bin:$PATH"
RUN set -ex \
ARG PYTHON_IMG_TAG
COPY --from=extract-deps \
/opt/python/requirements-ci.txt /opt/python/
RUN mv /home/appuser/.local/bin/* /usr/local/bin/ \
&& mv /home/appuser/.local/lib/python${PYTHON_IMG_TAG}/site-packages/* \
/usr/local/lib/python${PYTHON_IMG_TAG}/site-packages/ \
&& set -ex \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install \
-y --no-install-recommends \
"gosu" \
"git" \
&& rm -rf /var/lib/apt/lists/*
RUN mv /home/appuser/.local /root/.local
COPY --from=extract-deps \
/opt/python/requirements-ci.txt /opt/python/
RUN pip install --user --upgrade --no-warn-script-location \
&& rm -rf /var/lib/apt/lists/* \
&& pip install --upgrade --no-warn-script-location \
--no-cache-dir -r \
/opt/python/requirements-ci.txt \
&& rm -r /opt/python
# Pre-compile packages to .pyc (init speed gains)
RUN python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)"
&& rm -r /opt/python \
# Pre-compile packages to .pyc (init speed gains)
&& python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)"
# Override entrypoint, as not possible in Github action
ENTRYPOINT [""]
CMD [""]
Expand Down
113 changes: 0 additions & 113 deletions src/backend/alembic.ini

This file was deleted.

21 changes: 17 additions & 4 deletions src/backend/app-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

set -eo pipefail

while !</dev/tcp/${FMTM_DB_HOST:-fmtm-db}/5432;
do
sleep 1;
done;
wait_for_db() {
max_retries=30
retry_interval=5

for ((i = 0; i < max_retries; i++)); do
if </dev/tcp/${FMTM_DB_HOST:-fmtm-db}/5432; then
echo "Database is available."
return 0 # Database is available, exit successfully
fi
echo "Database is not yet available. Retrying in ${retry_interval} seconds..."
sleep ${retry_interval}
done

echo "Timed out waiting for the database to become available."
exit 1 # Exit with an error code
}

wait_for_db
exec "$@"
Loading
Loading