-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Liana64/main
Features: Gunicorn, CI, Docker, requirements
- Loading branch information
Showing
5 changed files
with
318 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
name: Docker Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags-ignore: | ||
- "*" | ||
pull_request: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- "*" | ||
|
||
jobs: | ||
build: | ||
if: "!github.event.head_commit.message || contains(github.event.head_commit.message, 'Feature') || contains(github.event.head_commit.message, 'feature') || contains(github.event.head_commit.message, 'Release') || contains(github.event.head_commit.message, 'release')" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Lowercase repository owner | ||
shell: bash | ||
run: echo "LOWERCASE_REPO_OWNER=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV | ||
|
||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: "${{ github.actor }}" | ||
password: "${{ secrets.GITHUB_TOKEN }}" | ||
|
||
- name: Build Image | ||
uses: docker/build-push-action@v6 | ||
id: build | ||
with: | ||
context: . | ||
platforms: "amd64" | ||
push: true | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
tags: | | ||
ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/unique-turker:${{ github.sha }} | ||
ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/unique-turker:latest | ||
labels: |- | ||
org.opencontainers.image.title="unique-turker" | ||
org.opencontainers.image.url=https://ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/unique-turker | ||
org.opencontainers.image.version="latest" | ||
org.opencontainers.image.revision=${{ github.sha }} | ||
org.opencontainers.image.vendor=${{ env.LOWERCASE_REPO_OWNER }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
FROM docker.io/library/python:3.12-alpine | ||
LABEL org.opencontainers.image.source="https://github.com/isaiasghezae/unique-turker-2" | ||
|
||
ARG TARGETPLATFORM | ||
ARG VERSION | ||
ARG CHANNEL | ||
|
||
ENV \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 \ | ||
PIP_ROOT_USER_ACTION=ignore \ | ||
PIP_NO_CACHE_DIR=1 \ | ||
PIP_DISABLE_PIP_VERSION_CHECK=1 \ | ||
PIP_BREAK_SYSTEM_PACKAGES=1 \ | ||
CRYPTOGRAPHY_DONT_BUILD_RUST=1 | ||
|
||
ENV UMASK="0002" \ | ||
TZ="Etc/UTC" \ | ||
EXPOSED_URL="REPLACE_ME" \ | ||
EXPOSED_PROTO="HTTPS" \ | ||
CONFIG_DB="/config/database.db" | ||
|
||
USER root | ||
|
||
WORKDIR /config | ||
VOLUME /config | ||
|
||
WORKDIR /app | ||
|
||
RUN apk add --no-cache \ | ||
bash \ | ||
catatonit \ | ||
coreutils \ | ||
curl \ | ||
jq \ | ||
nano \ | ||
tzdata \ | ||
git \ | ||
&& git clone https://github.com/isaiasghezae/unique-turker-2.git . \ | ||
&& pip install uv \ | ||
&& uv pip install --system \ | ||
flask \ | ||
flask-cors \ | ||
Flask-SQLAlchemy \ | ||
gunicorn \ | ||
&& chown -R root:root /app && chmod -R 755 /app \ | ||
&& if [ -f /config/database.db ]; then \ | ||
rm -f /app/instance/database.db; \ | ||
ln -s /config/database.db /app/instance/database.db; \ | ||
else \ | ||
cp /app/instance/database.db /config/database.db && \ | ||
rm -f /app/instance/database.db && \ | ||
ln -s /config/database.db /app/instance/database.db; \ | ||
fi \ | ||
&& chown -R root:root /app && chmod -R 755 /app \ | ||
&& chown -R nobody:nogroup /app && chmod -R 755 /config/database.db \ | ||
&& rm -rf /root/.cache /root/.cargo /tmp/* | ||
|
||
COPY ./dockerfiles/entrypoint.sh /entrypoint.sh | ||
|
||
USER nobody:nogroup | ||
|
||
EXPOSE 8080 | ||
|
||
ENTRYPOINT ["/usr/bin/catatonit", "--", "/entrypoint.sh"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
APP_DB="/app/instance/database.db" | ||
OUTPUT_FILE=/app/website/templates/output.html | ||
FULL_URL="${EXPOSED_PROTO,,}://${EXPOSED_URL}" | ||
|
||
if [[ "$EXPOSED_PROTO" != "HTTPS" && "$EXPOSED_PROTO" != "HTTP" ]]; then | ||
echo "Error: EXPOSED_PROTO must be either 'HTTPS' or 'HTTP'." | ||
exit 1 | ||
fi | ||
|
||
if [[ -z "$EXPOSED_URL" || "$EXPOSED_URL" == "REPLACE_ME" ]]; then | ||
echo "Error: EXPOSED_URL must be set." | ||
exit 1 | ||
fi | ||
|
||
|
||
echo "───────────────────────────────────────" | ||
create_symlink() { | ||
ln -s "$CONFIG_DB" "$APP_DB" | ||
if [ $? -eq 0 ]; then | ||
echo "Symbolic link created: $APP_DB -> $CONFIG_DB" | ||
else | ||
echo "Failed to create symbolic link." | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Check if /config/database.db exists | ||
if [ ! -f "$CONFIG_DB" ]; then | ||
echo "$CONFIG_DB does not exist. Copying from $APP_DB." | ||
|
||
# Check if the source database exists before copying | ||
if [ -f "$APP_DB" ]; then | ||
cp "$APP_DB" "$CONFIG_DB" | ||
if [ $? -eq 0 ]; then | ||
echo "Copied $APP_DB to $CONFIG_DB." | ||
else | ||
echo "Failed to copy $APP_DB to $CONFIG_DB." | ||
exit 1 | ||
fi | ||
else | ||
echo "Source database $APP_DB does not exist. Cannot copy." | ||
exit 1 | ||
fi | ||
|
||
# Create symbolic link | ||
create_symlink | ||
else | ||
echo "$CONFIG_DB already exists." | ||
echo $(du -h $CONFIG_DB) | ||
|
||
# Check if the application database exists before attempting to delete | ||
if [ -L "$APP_DB" ] || [ -f "$APP_DB" ]; then | ||
rm "$APP_DB" | ||
if [ $? -eq 0 ]; then | ||
echo "Deleted existing $APP_DB." | ||
else | ||
echo "Failed to delete $APP_DB." | ||
exit 1 | ||
fi | ||
else | ||
echo "$APP_DB does not exist. No need to delete." | ||
fi | ||
|
||
# Create symbolic link | ||
create_symlink | ||
fi | ||
echo "Setting EXPOSED_URL" | ||
sed -i.bak -e "s|var url = \"https://LINK-TO-YOUR-DATABASE.COM/check_worker_eligibility\";.*|var url = \"$FULL_URL/check_worker_eligibility\"; // IMPORTANT: This is where you put the link to your database|g" "$OUTPUT_FILE" | ||
echo "" | ||
echo "Done! Webserver is ready for use and accessible at:" | ||
echo $FULL_URL | ||
echo "───────────────────────────────────────" | ||
|
||
exec \ | ||
/usr/local/bin/gunicorn \ | ||
--bind 0.0.0.0:8080 main:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
blinker==1.9.0 | ||
click==8.1.7 | ||
flask==3.1.0 | ||
flask-cors==5.0.0 | ||
flask-sqlalchemy==3.1.1 | ||
greenlet==3.1.1 | ||
gunicorn==23.0.0 | ||
itsdangerous==2.2.0 | ||
jinja2==3.1.4 | ||
markupsafe==3.0.2 | ||
packaging==24.2 | ||
pip==24.3.1 | ||
sqlalchemy==2.0.36 | ||
typing-extensions==4.12.2 | ||
uv==0.5.7 | ||
werkzeug==3.1.3 |