Skip to content

Commit

Permalink
Merge pull request #159 from mjanez/feature/nginx-enhance
Browse files Browse the repository at this point in the history
Feature/nginx enhance
  • Loading branch information
mjanez authored Nov 8, 2024
2 parents 3ea275f + 33c6e23 commit 7bc377e
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 37 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,14 @@ PostgreSQL offers the command line tools [`pg_dump`](https://www.postgresql.org/
#### Backup service for db container
1. Create a new file called `ckan_backup_custom.sh` and open it in your preferred text editor.
2. Add the following code to the script, replacing the placeholders with your actual values:
2. Add the following code to the script, replacing the placeholders with your [`.env`](.env.example) values:
```bash
#!/bin/bash
# Set the necessary variables
CONTAINER_NAME="db"
DATABASE_NAME="ckandb"
DB_CONTAINER_NAME="ckan-docker-db-1"
CKAN_DB="ckandb"
POSTGRES_USER="postgres"
POSTGRES_PASSWORD="your_postgres_password"
BACKUP_DIRECTORY="/path/to/your/backup/directory"
Expand All @@ -573,7 +573,7 @@ PostgreSQL offers the command line tools [`pg_dump`](https://www.postgresql.org/
mkdir -p "$BACKUP_DIRECTORY/monthly/$YEAR-$MONTH"
# Run the backup command
docker exec -e PGPASSWORD=$POSTGRES_PASSWORD $CONTAINER_NAME pg_dump -U $POSTGRES_USER -Fc $DATABASE_NAME > "$BACKUP_DIRECTORY/monthly/$YEAR-$MONTH/ckan_backup_$DATE.dump"
docker exec -e PGPASSWORD=$POSTGRES_PASSWORD $DB_CONTAINER_NAME pg_dump -U $POSTGRES_USER -Fc $CKAN_DB > "$BACKUP_DIRECTORY/monthly/$YEAR-$MONTH/ckan_backup_$DATE.dump"
# Compress the dump files into a zip archive
cd "$BACKUP_DIRECTORY/monthly/$YEAR-$MONTH" || exit
Expand Down Expand Up @@ -637,7 +637,7 @@ If need to use a backup, restore it:
2. After cleaning the database you must do either [initialize it](https://docs.ckan.org/en/2.9/maintaining/database-management.html#initialization) or import a previously created dump.
```bash
docker exec -i -e PGPASSWORD=$POSTGRES_PASSWORD $POSTGRESQL_CONTAINER_NAME pg_restore -U $POSTGRES_USER --clean --if-exists -d $DATABASE_NAME < /path/to/your/backup/directory/ckan.dump
docker exec -i -e PGPASSWORD=$POSTGRES_PASSWORD $DB_CONTAINER_NAME pg_restore -U $POSTGRES_USER --clean --if-exists -d $CKAN_DB < /path/to/your/backup/directory/ckan.dump
```
3. Restart the `ckan` container.
Expand Down
11 changes: 8 additions & 3 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ ENV PROXY_CKAN_PROXY_PASS=http://${CKAN_COMPOSE_SERVICE}:${CKAN_PORT}
ENV NGINX_PORT=80
ENV NGINX_LOG_DIR=/var/log/nginx
ENV NGINX_DIR=/etc/nginx
ENV NGINX_SHARE_HTML_DIR=/usr/share/nginx/html

RUN mkdir -p ${NGINX_LOG_DIR} && \
mkdir -p ${NGINX_DIR}/certs
RUN mkdir -p ${NGINX_LOG_DIR} \
&& mkdir -p ${NGINX_DIR}/certs

# Copy configuration and static files
COPY setup/nginx.conf ${NGINX_DIR}/nginx.conf
COPY setup/index.html /usr/share/nginx/html/index.html
COPY setup/default.conf.template ${NGINX_DIR}/templates/default.conf.template
COPY setup/ckan-local.* ${NGINX_DIR}/certs/
COPY setup/html/index.html setup/html/robots.txt ${NGINX_SHARE_HTML_DIR}/

# Replace $PROXY_CKAN_LOCATION and $PROXY_PYCSW_LOCATION in index.html
RUN sed -i "s|/catalog|${PROXY_CKAN_LOCATION}|g; s|/csw|${PROXY_PYCSW_LOCATION}|g" ${NGINX_SHARE_HTML_DIR}/index.html

EXPOSE ${NGINX_PORT}
15 changes: 8 additions & 7 deletions nginx/setup/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ server {
ssl_certificate /etc/nginx/certs/ckan-local.crt;
ssl_certificate_key /etc/nginx/certs/ckan-local.key;

root $NGINX_SHARE_HTML_DIR;
index index.html;

# TLS 1.2 & 1.3 only
ssl_protocols TLSv1.2 TLSv1.3;

Expand Down Expand Up @@ -70,12 +73,10 @@ server {
error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 425 426 428 429 431 451 500 501 502 503 504 505 506 507 508 510 511 /error.html;

# redirect server error pages to the static page /error.html
#
location = /error.html {
ssi on;
internal;
auth_basic off;
root /usr/share/nginx/html;

# robots.txt
location = /robots.txt {
add_header Content-Type text/plain;
root $NGINX_SHARE_HTML_DIR;
}

}
1 change: 1 addition & 0 deletions nginx/setup/html/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
155 changes: 155 additions & 0 deletions nginx/setup/html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CKAN Docker Landing Page</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
text-align: center;
background-color: #f4f4f4;
color: #333;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
min-height: 100vh;
}
header {
background-color: #003164;
color: white;
padding: 20px 0;
width: 100%;
}
h2 {
font-weight: bold;
font-size: 32px;
margin: 0;
}
.content {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
flex-wrap: wrap;
}
a {
text-decoration: none;
color: inherit;
}
li {
display: inline-block;
margin: 20px;
width: 450px;
height: 400px;
background-color: white;
border: 1px solid #00316426;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
transition: transform 0.2s, color 0.2s;
border-radius: 5%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
li:hover {
transform: translateY(-10px);
color: #003164;
}
li img {
display: block;
margin: 20px auto;
max-width: 150px;
}
li p {
display: block;
font-weight: bold;
text-decoration: none;
font-size: 30px;
color: #a8a6a3;
margin: 10px 0;
}
li:hover p {
color: #003164;
}
footer {
background-color: #003164;
color: white;
padding: 10px 0;
width: 100%;
position: fixed;
bottom: 0;
}
/* Style for the icon button */
.icon-button {
display: inline-flex;
align-items: center;
justify-content: center;
text-decoration: none;
color: white;
border-radius: 50%;
padding: 0.4rem;
transition: background-color 0.3s, color 0.3s;
}

/* Hover effect */
.icon-button:hover {
background-color: rgb(47 136 163 / 40%);
color: white;
text-decoration: none;
}

/* Style for the icon */
.icon-button svg {
width: 24px;
height: 24px;
fill: white;
}
.sct-about-figures-alt-card-icon {
height: 100%;
width: 30%;
float: left;
border-radius: 4px 30px 30px 4px / 4px 40px 40px 4px;
display: flex;
justify-content: center;
align-items: center;
background-color: #003164;
}
</style>
</head>
<body>
<header>
<h2>CKAN Docker Landing Page</h2>
</header>
<div class="content">
<ul>
<a href="/catalog">
<li>
<img src="https://raw.githubusercontent.com/mjanez/ckanext-schemingdcat/21550f131bfcd7c35e095a2c2caa766bf9f9d69d/ckanext/schemingdcat/public/images/default/ckan-logo.png" alt="Open Data Catalog">
<p>Open Data portal</p>
</li>
</a>
<a href="/csw">
<li>
<img src="https://www.ogc.org/wp-content/uploads/2023/03/OGC-1.svg" alt="CSW Endpoint">
<p>CSW Endpoint</p>
</li>
</a>
</ul>
</div>
<footer>
<a href="https://github.com/mjanez/ckan-docker" class="icon-button">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3 .3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5 .3-6.2 2.3zm44.2-1.7c-2.9 .7-4.9 2.6-4.6 4.9 .3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3 .7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3 .3 2.9 2.3 3.9 1.6 1 3.6 .7 4.3-.7 .7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3 .7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3 .7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>
</a>
</footer>
</body>
</html>
File renamed without changes.
22 changes: 0 additions & 22 deletions nginx/setup/index.html

This file was deleted.

0 comments on commit 7bc377e

Please sign in to comment.