Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dockerfile devenvironment and some test script and docs #29

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# smart_proxy_realm_ad_plugin

Welcome to the project! This repository contains smart_proxy_realm_ad_plugin.

## Getting Started

For detailed onboarding instructions, please refer to the [ONBOARDING.md](ONBOARDING.md) file.

## Prerequisites

- Docker
- Git

## Quick Start

1. **Clone your fork**

```sh
git clone https://github.com/your-username/smart_proxy_realm_ad_plugin.git
cd smart_proxy_realm_ad_plugin
```

2. **Install the prerequisites**

Ensure you have Docker and Git installed on your machine. You can follow the official installation guides:

- [Docker Installation](https://docs.docker.com/get-docker/)
- [Git Installation](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)

3. **Build the Docker image**

Use Docker to build the image for the development environment.

```sh
docker build -t smart_proxy_realm_ad_plugin .
```

4. **Run the Docker container**

Start the Docker container with the necessary configurations.

```sh
docker run -it --rm --name smart_proxy_realm_ad_plugin -v $(pwd):/app -w /app smart_proxy_realm_ad_plugin
```

This command will run the Docker container interactively, mount the current directory to `/app` inside the container, and set the working directory to `/app`.

5. **Install dependencies**

Inside the running Docker container, install the necessary dependencies.

```sh
bundle install
```

6. **Run tests**

To ensure everything is set up correctly, you can run the tests inside the Docker container.

```sh
bundle exec rake test
```

7. **Start developing**

You are now ready to start developing! Make your changes and see them reflected in the running application.

## Additional Resources

- [Foreman Documentation](https://theforeman.org/documentation.html)
- [Foreman Smart Proxy Documentation](https://theforeman.org/manuals/latest/index.html#4.3SmartProxies)
- [Foreman Community](https://community.theforeman.org/)

72 changes: 72 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
FROM ubuntu:22.04

# Define package lists
ENV RUBY_PACKAGES="ruby ruby-dev gem"
ENV BUILD_TOOLS="automake autoconf gcc make libc-dev"
ENV RADCLI_DEPENDENCIES="libkrb5-dev libldap2-dev libsasl2-dev"
ENV TESTING_TOOLS="adcli krb5-user ldap-utils dnsutils ltrace strace"
ENV VERSION_CONTROL="git"
ENV NETWORK_TOOLS="iputils-ping nmap tshark"
ENV UTILITY_TOOLS="wget gnupg sudo"

# Define DNS resolver variables
ENV DNS_SERVER=192.168.3.1
ENV DNS_SEARCH=lab.local
ENV DOMAIN="lab.local"

# Preconfigure krb5-config and tshark to avoid interactive prompts
RUN echo "krb5-config krb5-config/default_realm string LAB.LOCAL" | debconf-set-selections && \
echo "resolvconf resolvconf/linkify-resolvconf boolean false" | debconf-set-selections && \
echo "wireshark-common wireshark-common/install-setuid boolean true" | debconf-set-selections && \
echo "wireshark-common wireshark-common/install-setuid boolean true" | debconf-set-selections

# Copy the DNS setup script
COPY ./scripts/set_dns.sh /usr/local/bin/set_dns.sh
RUN chmod +x /usr/local/bin/set_dns.sh

# Install packages
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get install -y --no-install-recommends \
$RADCLI_DEPENDENCIES \
$RUBY_PACKAGES \
$BUILD_TOOLS \
$LIBRARIES \
$TESTING_TOOLS \
$NETWORK_TOOLS \
$VERSION_CONTROL \
$UTILITY_TOOLS && \
rm -rf /var/lib/apt/lists/*

# Install foreman-proxy nightly
RUN apt update && \
apt install -y wget ca-certificates && \
cd /tmp && wget https://apt.puppet.com/puppet7-release-jammy.deb && \
apt install -y /tmp/puppet7-release-jammy.deb && \
wget https://deb.theforeman.org/foreman.asc -O /etc/apt/trusted.gpg.d/foreman.asc && \
echo "deb http://deb.theforeman.org/ jammy nightly" | tee /etc/apt/sources.list.d/foreman.list && \
echo "deb http://deb.theforeman.org/ jammy nightly" | tee /etc/apt/sources.list.d/foreman.list && \
echo "deb http://deb.theforeman.org/ plugins nightly" | tee -a /etc/apt/sources.list.d/foreman.list && \
apt update -y && \
apt upgrade -y

# Create a non-root user with sudo access
RUN groupadd -r devuser && useradd -r -g devuser -m -s /bin/bash devuser && \
usermod -aG sudo devuser && \
echo "devuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# Set the user to the newly created non-root user
USER devuser

# Set the working directory
WORKDIR /home/devuser

# Install oh-my-bash for devuser
RUN git clone https://github.com/ohmybash/oh-my-bash.git /home/devuser/.oh-my-bash && \
cp /home/devuser/.oh-my-bash/templates/bashrc.osh-template /home/devuser/.bashrc && \
chown -R devuser:devuser /home/devuser/.oh-my-bash /home/devuser/.bashrc

WORKDIR /app

# Set the entrypoint to the DNS setup script
ENTRYPOINT ["/usr/local/bin/set_dns.sh"]
CMD ["/bin/bash"]
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
IMAGE_NAME=smart_proxy_realm_ad_plugin:master
CONTAINER_NAME=smart_proxy_realm_ad_plugin-dev

# Default goal
.DEFAULT_GOAL := help

# Phony targets
.PHONY: help build default shell clean stop logs rebuild restart test

## Default target to build and run
default: build run

help: ## Diplay this help
@echo "Usage: make [target]"
@echo "Targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

build: ## Build from Dockerfile
docker build -t $(IMAGE_NAME) .

rebuild: ## Build without cache
docker build -t $(IMAGE_NAME) --no-cache .

run: ## Run in the background
docker inspect $(CONTAINER_NAME) >/dev/null 2>&1 && docker rm -f $(CONTAINER_NAME) || true
docker run --name=$(CONTAINER_NAME) -v $(PWD):/app -d $(IMAGE_NAME) sleep infinity

shell: build run ## Open a shell in the running container
docker exec -it $(CONTAINER_NAME) /bin/bash

stop: ## Stop the running container
docker stop $(CONTAINER_NAME) || true

restart: stop run ## Restart the container

clean: ## clean
docker rm -f $(CONTAINER_NAME) >> /dev/null 2>&1 || true
docker rmi -f $(IMAGE_NAME) >> /dev/null 2>&1 || true

## Use inside the container

local-build: ## Inside Container: Build a local gem inside the container
sudo gem build
#sudo gem install radcli
sudo gem install smart_proxy_realm_ad_plugin-0.1.gem
sudo find /var/lib -name radcli*
sudo find /var -name provider.rb
sudo find /var -name realm*

93 changes: 93 additions & 0 deletions docs/INTRO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Getting Started with the [`smart_proxy_realm_ad_plugin`]

This tutorial will guide you through the steps to build, run, and use the [`smart_proxy_realm_ad_plugin`]

This container is based on Ubuntu 22.04 and includes various development tools, libraries, and configurations for working with Kerberos and LDAP.

## Prerequisites

- Docker installed on your machine.
- Internet connection to pull base images and clone repositories.

## Step 1: Clone the Repository

First, clone the repository containing the Dockerfile and related scripts.

```sh
git clone https://github.com/your-repo/smart_proxy_realm_ad_plugin.git
cd smart_proxy_realm_ad_plugin
```

## Step 2: Build the Docker Image

Build the Docker image using the provided Dockerfile. This step will install all necessary packages and configure the environment.

```sh
docker build -t smart_proxy_realm_ad_plugin:master .
```

## Step 3: Run the Docker Container

Run the container in the background. This command will start the container and keep it running.

```sh
docker run --name smart_proxy_realm_ad_plugin-dev -d smart_proxy_realm_ad_plugin:master sleep infinity
```

## Step 4: Access the Container

Open a shell inside the running container to start using it.

```sh
docker exec -it smart_proxy_realm_ad_plugin-dev /bin/bash
```

## Step 5: Verify the Environment

Once inside the container, you can verify that the environment is set up correctly.

1. **Check Installed Packages**:
```sh
dpkg -l | grep -E 'ruby|automake|autoconf|gcc|make|libkrb5-dev|libldap2-dev|libsasl2-dev|adcli|krb5-user|ldap-utils|dnsutils|git'
```

2. **Check DNS Configuration**:
```sh
cat /etc/resolv.conf
```

3. **Check Oh-My-Bash Installation**:
```sh
echo $OSH
```

## Step 6: Run Tests (Optional)

If you have tests to run inside the container, you can execute them as follows:

```sh
docker exec smart_proxy_realm_ad_plugin-dev /bin/bash -c "cd /path/to/tests && ./run_tests.sh"
```

## Step 7: Clean Up

When you are done, you can stop and remove the container, and optionally remove the image.

1. **Stop the Container**:
```sh
docker stop smart_proxy_realm_ad_plugin-dev
```

2. **Remove the Container**:
```sh
docker rm smart_proxy_realm_ad_plugin-dev
```

3. **Remove the Image** (optional):
```sh
docker rmi smart_proxy_realm_ad_plugin:master
```

## Summary

You have successfully built and run the [`smart_proxy_realm_ad_plugin`] container. You can now use this container for development and testing purposes, with all necessary tools and configurations pre-installed.
Loading
Loading