Skip to content

Commit

Permalink
microcloud/charms/setup: local image server for faster development it…
Browse files Browse the repository at this point in the history
…erations

Signed-off-by: Gabriel Mougard <gabriel.mougard@canonical.com>
  • Loading branch information
gabrielmougard committed Sep 8, 2023
1 parent 1e59c10 commit 834dc2d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions microcloud/charms/setup/local-maas-image-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:latest

COPY nginx.conf /etc/nginx/nginx.conf
47 changes: 47 additions & 0 deletions microcloud/charms/setup/local-maas-image-server/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

# Improve performance by turning on sendfile and adjusting other parameters
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
client_max_body_size 5g;

# Compression reduces the response size and improves the speed
gzip on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

server {
listen 80;
server_name 0.0.0.0;

# Point to the Simplestreams data directory
root /usr/share/maas/images/ephemeral-v3/stable;

location / {
expires 30d;
add_header Cache-Control "public, max-age=2592000";
try_files $uri $uri/ =404;
}
}
}
26 changes: 26 additions & 0 deletions microcloud/charms/setup/local-maas-image-server/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

HOST_PATH="/usr/share/maas/images"

if [ ! -d "$HOST_PATH" ]; then
echo "Warning: Directory $HOST_PATH does not exist. Creating folder..."
sudo mkdir -p $HOST_PATH
fi

KEYRING_FILE=/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg
IMAGE_SRC=https://images.maas.io/ephemeral-v3/stable
IMAGE_DIR=/usr/share/maas/images/ephemeral-v3/stable

sudo sstream-mirror \
--keyring=$KEYRING_FILE $IMAGE_SRC $IMAGE_DIR \
'arch=amd64' 'release~(jammy)' --max=1 --progress

sudo sstream-mirror \
--keyring=$KEYRING_FILE $IMAGE_SRC $IMAGE_DIR \
'os~(grub*|pxelinux)' --max=1 --progress

docker build -t nginx-maas-image-server .
docker run --name local-maas-image-server \
-d -p 5000:80 \
-v $HOST_PATH/ephemeral-v3/stable:/usr/share/maas/images/ephemeral-v3/stable \
nginx-maas-image-server

0 comments on commit 834dc2d

Please sign in to comment.