# Generated by ChatGPT
# Use a minimal base image
FROM alpine:3.18

# Install OpenSSH server and create test user
RUN apk add --no-cache openssh && \
    adduser -D -g '' test && \
    echo "test:test" | chpasswd

# Enable password authentication in SSH server
RUN sed -i 's/#PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config

# Generate SSH keys for the server
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' && \
    ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' && \
    ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''

# Install dependencies (imagemagick and font packages)
RUN apk add --no-cache imagemagick fontconfig ttf-dejavu

# Expose SSH port
EXPOSE 22

# Copy the public key to the authorized keys
COPY test_id_rsa.pub /home/test/.ssh/authorized_keys

# Set the correct permissions for the authorized keys file
RUN chown test:test /home/test/.ssh/authorized_keys && \
    chmod 600 /home/test/.ssh/authorized_keys

# Start the SSH server
CMD ["/usr/sbin/sshd", "-D"]

# Copy the script that generates PNG images
COPY generate_images.sh /usr/local/bin/generate_images.sh

# Run the script to generate PNG images and place them in test's home folder
RUN chmod +x /usr/local/bin/generate_images.sh && \
    "/usr/local/bin/generate_images.sh" test

RUN chown -R test /home/test/images
RUN chgrp -R test /home/test/images
