aboutsummaryrefslogtreecommitdiff
path: root/Dockerfile.debian
blob: f5b40ca877e3d9f7ecee226cd26801cebbeab838 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# This Dockerfile sets up a simple SSH server for hosting git repositories. It installs the necessary packages, creates the required directories, and configures SSH to allow access using authorized keys.

# Start with a base Debian image
FROM debian:13.4

# Install dependencies and clean up apt cache to reduce image size
RUN apt-get update && apt-get install -y --no-install-recommends \
    openssh-server \
    git \
    cron \
    jq \
    && rm -rf /var/lib/apt/lists/*

# Create the privilage separation directory as openssh-server post-install script doesn't do it in docker build context
RUN mkdir -p /var/run/sshd

# Create a git user and set up the home directory
RUN useradd -m -s /bin/bash git

# Create the repositories directory and set appropriate permissions
RUN mkdir -p /repositories && chown git:git /repositories

# Disallow password authentication for security reasons
RUN echo "PasswordAuthentication no" >> /etc/ssh/sshd_config

# Copy the entrypoint script into the container
COPY entrypoint.bash /

# Copy cron jobs
COPY etc/cron.d/* /etc/cron.d/

# Set appropriate permissions for the cron jobs
RUN chmod 0644 /etc/cron.d/*

# Copy scripts
COPY scripts/* /scripts/

# Set appropriate permissions for the scripts
RUN chmod +x /scripts/*

# Copy git home overlay
COPY home/git/* /home/git/

# Copy git-wrapper
COPY usr/local/bin/git-wrapper /usr/local/bin/git-wrapper

# Set appropriate permissions for the git-wrapper
RUN chmod +x /usr/local/bin/git-wrapper

# Add our git-wrapper to a new Match block in the sshd_config
RUN echo "Match User git" >> /etc/ssh/sshd_config && \
    echo "    ForceCommand /usr/local/bin/git-wrapper" >> /etc/ssh/sshd_config

# Make the entrypoint script executable
RUN chmod +x /entrypoint.bash

# Expose port 22 for SSH access
EXPOSE 22

# Define our entrypoint
ENTRYPOINT [ "/entrypoint.bash" ]