Add docker image

This commit is contained in:
2024-09-08 19:46:41 +10:00
parent cd848fe6aa
commit 2007232aea
5 changed files with 125 additions and 2 deletions
+46
View File
@@ -0,0 +1,46 @@
# Use an official Python runtime as a parent image
FROM python:3.12-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE url_manager.settings
# Set work directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
nodejs \
npm \
gettext \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt /app/
RUN pip install --upgrade pip && pip install -r requirements.txt
# Copy project
COPY . /app/
# Install Tailwind CSS dependencies
RUN python manage.py tailwind install
# Build Tailwind CSS
RUN python manage.py tailwind build
# Collect static files
RUN python manage.py collectstatic --noinput
# Compile translation messages
RUN python manage.py compilemessages --locale=zh_Hans
# Create data directory for SQLite database
RUN mkdir -p /app/data && chmod 777 /app/data
# Expose port 8000
EXPOSE 8000
# Run the application
CMD ["gunicorn", "url_manager.wsgi:application", "--bind", "0.0.0.0:8000"]
+76
View File
@@ -0,0 +1,76 @@
# URL Manager
URL Manager is a Django-based web application for managing and tracking short URLs.
## Features
- Create, edit, and delete short URL links
- Track click statistics for each link
- Search functionality for quick access to links
- Internationalization support (English and Simplified Chinese)
- Responsive design using Tailwind CSS
## Prerequisites
- Docker and Docker Compose
## Installation and Setup with Docker
1. Clone the repository:
```
git clone https://github.com/yourusername/url-manager.git
cd url-manager
```
2. Build the Docker image:
```
docker build -t url-manager .
```
3. Create a Docker volume for persistent database storage:
```
docker volume create url-manager-data
```
4. Run the Docker container:
```
docker run -d --name url-manager-container -p 8000:8000 -v url-manager-data:/app/data url-manager
```
5. Initialize the database and create a superuser:
```
docker exec -it url-manager-container python manage.py migrate
docker exec -it url-manager-container python manage.py createsuperuser
```
6. Open your web browser and navigate to `http://localhost:8000` to access the application.
## Usage
- To create a new short URL, click on the "Create New Link" button on the home page.
- To edit or delete a link, use the corresponding buttons in the link list.
- To view detailed statistics for a link, click on the "Details" button.
- Use the search bar in the navigation to quickly find links by alias or original URL.
## Admin Interface
To access the admin interface:
1. Go to `http://localhost:8000/admin`
2. Log in with the superuser account you created earlier
## Changing the Language
To switch between English and Simplified Chinese, use the language selector in the navigation bar.
## Persistent Data
The SQLite database is stored in the Docker volume `url-manager-data`. This ensures that your data persists even if the container is stopped or removed. To backup your data, you can copy the contents of this volume.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License.
+1 -1
View File
@@ -89,7 +89,7 @@
</tr>
{% empty %}
<tr>
<td colspan="5" class="px-6 py-4 whitespace-nowrap text-center text-gray-500">{% trans "No links available" %}</td>
<td colspan="7" class="px-6 py-4 whitespace-nowrap text-center text-gray-500">{% trans "No links available" %}</td>
</tr>
{% endfor %}
</tbody>
Binary file not shown.
+2 -1
View File
@@ -58,12 +58,13 @@ ALLOWED_HOSTS = []
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'NAME': '/app/data/db.sqlite3', # Updated path
}
}
# 静态文件设置
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
# 默认自动字段类型
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'