Skip to content

Commit ee0e36c

Browse files
authored
Merge pull request #343 from threefoldtech/funkwhale
fix ssh not working in funkwhale image
2 parents 0b7815a + b5e20d4 commit ee0e36c

File tree

7 files changed

+44
-67
lines changed

7 files changed

+44
-67
lines changed

tfgrid3/funkwhale/Dockerfile

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ RUN apt-get update && \
1111
gettext \
1212
gnupg \
1313
openssh-server \
14-
ufw \
15-
nginx \
16-
certbot \
17-
python3-certbot-nginx && \
14+
ufw && \
1815
apt-get clean && \
1916
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
2017

@@ -26,10 +23,8 @@ RUN curl -s https://api.github.com/repos/threefoldtech/zinit/releases/latest | \
2623
chmod +x /sbin/zinit
2724

2825
# Copy configuration scripts
29-
COPY scripts/ufw.sh /usr/local/bin/
30-
COPY scripts/dockerd.sh /usr/local/bin/
31-
COPY scripts/start-fk.sh /usr/local/bin/
32-
RUN chmod +x /usr/local/bin/ufw.sh /usr/local/bin/dockerd.sh /usr/local/bin/start-fk.sh
26+
COPY scripts/* /usr/local/bin/
27+
RUN chmod +x /usr/local/bin/*.sh
3328

3429
# Add Zinit configuration files
3530
ADD zinit /etc/zinit/
@@ -48,8 +43,8 @@ RUN apt-get update && \
4843
RUN apt-get clean && \
4944
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
5045

51-
# Expose ports for HTTP and SSH access
52-
EXPOSE 5000 222
46+
# Expose ports for HTTP access
47+
EXPOSE 5000
5348

5449
# Command to run Zinit in the container
5550
CMD ["/sbin/zinit", "init", "--container"]

tfgrid3/funkwhale/README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,30 @@ Convert the docker image to Flist is using [Docker Hub Converter tool](https://h
2424

2525
## Environment Variables
2626

27-
Several environment variables need to be configured before deploying Funkwhale:
27+
Several environment variables need to be configured before deploying Funkwhale. SMTP configuration is optional—if not configured, Funkwhale will still function, but it will not send any emails (e.g., notifications, password resets).
2828

29+
### **Required for Basic Functionality**
2930
- `FUNKWHALE_SUPERUSER_NAME`: The username for the Funkwhale superuser.
3031
- `FUNKWHALE_SUPERUSER_EMAIL`: The email for the superuser account.
31-
- `FUNKWHALE_SUPERUSER_PASSWORD`: Password for the superuser account.
32-
- `FUNKWHALE_VERSION`: The version of Funkwhale to use (default: `1.4.0`).
32+
- `FUNKWHALE_SUPERUSER_PASSWORD`: The password for the superuser account.
3333
- `Domain`: The domain name for the Funkwhale instance (e.g., `funkwhale.example.com`).
3434
- `DJANGO_SECRET_KEY`: A unique secret key for Django. This environment variable is generated automatically by the **start script**.
3535

36-
These variables are passed via `.env` files or Zinit service configurations. Ensure they are set properly before deployment.
36+
### **Optional for SMTP Configuration**
37+
If you want Funkwhale to send emails, such as notifications or password resets, you need to configure the following variables:
3738

38-
## SSL Configuration
39-
This setup uses Certbot to generate and configure SSL certificates for your domain. Ensure the domain is properly configured with DNS settings that point to your server. The certificates are generated automatically during the deployment process.
39+
- `EMAIL_HOST`: The SMTP server address (e.g., `smtp.sendgrid.net`).
40+
- `EMAIL_PORT`: The port used by the SMTP server (e.g., `587`).
41+
- `EMAIL_USERNAME`: The username for SMTP authentication (e.g., `apikey` for SendGrid).
42+
- `EMAIL_PASSWORD`: The password or API key for SMTP authentication.
43+
- `EMAIL_PROTOCOL`: The protocol used for email communication. Supported options:
44+
- `smtp`: Plain SMTP communication.
45+
- `smtp+ssl`: SMTP with SSL encryption (port `465`).
46+
- `smtp+tls`: SMTP with TLS encryption (port `587`).
47+
- `DEFAULT_FROM_EMAIL`: The default sender email address (e.g., `peter@funkwhale-test.com`).
4048

49+
If these variables are not set, Funkwhale will default to outputting emails to the console (`consolemail://`), and emails will not actually be sent.
50+
51+
### **Passing Environment Variables**
52+
These environment variables are passed via `.env` files or Zinit service configurations. Ensure they are set properly before deployment to guarantee correct operation.
4153

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Path to the .env file
4+
ENV_FILE="/srv/funkwhale/.env"
5+
6+
# Check if all required variables are set
7+
if [[ -z "$EMAIL_HOST" || -z "$EMAIL_PORT" || -z "$EMAIL_USERNAME" || -z "$EMAIL_PASSWORD" || -z "$EMAIL_PROTOCOL" || -z "$DEFAULT_FROM_EMAIL" ]]; then
8+
echo "Missing required SMTP variables. Disabling SMTP."
9+
else
10+
echo "All required SMTP variables are set. Configuring SMTP."
11+
EMAIL_CONFIG="${EMAIL_PROTOCOL}://${EMAIL_USERNAME}:${EMAIL_PASSWORD}@${EMAIL_HOST}:${EMAIL_PORT}"
12+
sed -i "/^# EMAIL_CONFIG=dummymail/s|^# EMAIL_CONFIG=.*|EMAIL_CONFIG=${EMAIL_CONFIG}|" "$ENV_FILE"
13+
sed -i "/^# DEFAULT_FROM_EMAIL=/s|^# DEFAULT_FROM_EMAIL=.*|DEFAULT_FROM_EMAIL=${DEFAULT_FROM_EMAIL}|" "$ENV_FILE"
14+
fi

tfgrid3/funkwhale/scripts/start-fk.sh

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ set -ex
44
# Check if FUNKWHALE_VERSION is set, if not, default to 1.4.0
55
FUNKWHALE_VERSION=${FUNKWHALE_VERSION:-1.4.0}
66

7-
# Change to Funkwhale directory
7+
# Create and Change to Funkwhale directory
8+
mkdir /srv/funkwhale/
89
cd /srv/funkwhale/
910

1011
# Download the Docker Compose and environment files for the specified version
@@ -21,7 +22,10 @@ sed -i "s#^DJANGO_SECRET_KEY=.*#DJANGO_SECRET_KEY=$DJANGO_SECRET#" .env
2122
# Add environment variables to the .env file
2223
sed -i "s#^FUNKWHALE_VERSION=.*#FUNKWHALE_VERSION=$FUNKWHALE_VERSION#" .env
2324
sed -i "s#^FUNKWHALE_HOSTNAME=.*#FUNKWHALE_HOSTNAME=$Domain#" .env
25+
sed -i 's/^FUNKWHALE_API_IP=.*/FUNKWHALE_API_IP=0.0.0.0/' .env
2426

27+
# Setting SMTP Config
28+
bash /usr/local/bin/configure-smtp.sh
2529
# Pull the latest Docker images for Funkwhale
2630
docker-compose pull
2731

@@ -40,43 +44,3 @@ EOF
4044

4145
# Start Funkwhale services
4246
docker-compose up -d
43-
44-
# Check if $Domain is set before proceeding with SSL generation
45-
if [ -z "$Domain" ]; then
46-
echo "No Domain provided. Skipping SSL setup and exiting."
47-
exit 0
48-
fi
49-
50-
# Download and apply the Funkwhale Nginx proxy configuration
51-
curl -L -o /etc/nginx/funkwhale_proxy.conf "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$FUNKWHALE_VERSION/deploy/funkwhale_proxy.conf"
52-
curl -L -o /etc/nginx/sites-available/funkwhale.template "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$FUNKWHALE_VERSION/deploy/docker.proxy.template"
53-
54-
# Apply environment variables to the Nginx template and create the final Nginx configuration
55-
set -a && source /srv/funkwhale/.env && set +a
56-
envsubst "`env | awk -F = '{printf \" $%s\", $$1}'`" < /etc/nginx/sites-available/funkwhale.template > /etc/nginx/sites-available/funkwhale.conf
57-
58-
# Comment out SSL cert lines temporarily to allow HTTP access before SSL setup
59-
sed -i "s/listen 443 ssl http2\;/#listen 443 ssl http2\;/" /etc/nginx/sites-available/funkwhale.conf
60-
sed -i "s/listen \[::\]:443 ssl http2;/#listen \[::\]:443 ssl http2;/" /etc/nginx/sites-available/funkwhale.conf
61-
sed -i "s/ssl_certificate/\#ssl_certificate/" /etc/nginx/sites-available/funkwhale.conf
62-
63-
# Enable the Funkwhale Nginx site and create a backup of the current configuration
64-
ln -s /etc/nginx/sites-available/funkwhale.conf /etc/nginx/sites-enabled/
65-
cp /etc/nginx/sites-available/funkwhale.conf /etc/nginx/sites-available/funkwhale.conf.bak
66-
67-
# Generate SSL certificate using Certbot
68-
certbot --nginx -d $Domain --non-interactive --agree-tos --register-unsafely-without-email
69-
70-
# Restore the original Nginx configuration from the backup
71-
mv /etc/nginx/sites-available/funkwhale.conf.bak /etc/nginx/sites-available/funkwhale.conf
72-
73-
# Uncomment the SSL lines after Certbot finishes
74-
sed -i "s/\#ssl_certificate/ssl_certificate/" /etc/nginx/sites-available/funkwhale.conf
75-
sed -i "s/\#listen/listen/" /etc/nginx/sites-available/funkwhale.conf
76-
77-
# Add HTTP to HTTPS redirection in the Nginx configuration
78-
sed -i "11a \ if (\$host = $Domain) {\n return 301 https://\$host\$request_uri;\n }" /etc/nginx/sites-available/funkwhale.conf
79-
80-
# Restart Nginx to apply the New SSL configuration
81-
zinit stop nginx
82-
zinit start nginx

tfgrid3/funkwhale/scripts/ufw.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ ufw default deny incoming
55
ufw default allow outgoing
66
ufw allow ssh
77
ufw limit ssh
8-
ufw allow 443
9-
ufw allow 80
8+
ufw allow 5000

tfgrid3/funkwhale/zinit/nginx.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

tfgrid3/funkwhale/zinit/sshkey.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
exec: |
22
bash -c '
3-
if [ ! -z "$SSH_KEY" ]; then
43
mkdir -p /var/run/sshd
54
mkdir -p /root/.ssh
65
touch /root/.ssh/authorized_keys
7-
86
chmod 700 /root/.ssh
97
chmod 600 /root/.ssh/authorized_keys
10-
fi
11-
'
8+
'
129
oneshot: true

0 commit comments

Comments
 (0)