Skip to content
Draft
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
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
args:
- --allow-multiple-documents
- id: destroyed-symlinks
- id: end-of-file-fixer
- id: mixed-line-ending
args:
- --fix=lf
- id: detect-private-key
- id: check-toml
- id: pretty-format-json
args:
- --autofix
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
5 changes: 4 additions & 1 deletion beaker-tests/DockerTestEnv/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ RUN echo 'export LANG=en_US.UTF-8' >> /root/.bashrc
RUN echo 'set -g history-limit 40960' > /root/.tmux.conf

COPY bashrc /root/.bashrc_copr
COPY setup-local-copr.sh /usr/local/bin/setup-local-copr

RUN echo "source /root/.bashrc_copr" >> /root/.bashrc
RUN chmod +x /usr/local/bin/setup-local-copr \
&& echo "source /root/.bashrc_copr" >> /root/.bashrc

# Default to staging, can be overridden at runtime with setup-local-copr
RUN echo -e "[tested-copr]\nhostname = copr.stg.fedoraproject.org\nprotocol = https\nport = 443\n" \
> /etc/dnf/plugins/copr.d/tested-copr.conf

Expand Down
36 changes: 35 additions & 1 deletion beaker-tests/DockerTestEnv/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
.PHONY : build run sh start stop del
.PHONY: build run run-local sh start stop del help

mkfile_path:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

CONTAINER_NAME ?= test-env
CONTAINER_ENGINE ?= $(shell command -v podman 2> /dev/null || echo docker)

help:
@echo "COPR Test Environment"
@echo ""
@echo "Targets:"
@echo " build Build test container image"
@echo " run Run container (for staging/remote testing)"
@echo " run-local Run container with host network (for local podman-kube)"
@echo " sh Open shell in container"
@echo " start/stop Start/stop container"
@echo " del Delete container"
@echo ""
@echo "For local podman-kube testing:"
@echo " 1. make build"
@echo " 2. make run-local"
@echo " 3. make sh"
@echo " 4. Inside container: setup-local-copr"
@echo ""

build:
$(CONTAINER_ENGINE) build -t test-env-image .

bld: build

# Standard run - for staging/remote instances
run:
$(CONTAINER_ENGINE) run \
-dit \
Expand All @@ -19,6 +38,21 @@ run:
-w /root/ \
test-env-image

# Run with host network - for local podman-kube testing
# This allows the container to access localhost:5000 etc.
run-local:
$(CONTAINER_ENGINE) run \
-dit \
-v $(mkfile_path)/../..:/root/copr:z \
--name="$(CONTAINER_NAME)" \
-h $(CONTAINER_NAME) \
-w /root/ \
--network=host \
--add-host=frontend:127.0.0.1 \
--add-host=backend-httpd:127.0.0.1 \
--add-host=distgit:127.0.0.1 \
test-env-image

sh:
$(CONTAINER_ENGINE) exec $(CONTAINER_NAME) rm -f /run/nologin
$(CONTAINER_ENGINE) exec -u root -it $(CONTAINER_NAME) script -qc 'bash' /dev/null
Expand Down
29 changes: 20 additions & 9 deletions beaker-tests/DockerTestEnv/bashrc
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
# This file is sourced in /root/.bashrc inside the container

if ! test -f "$HOME/.config/copr"; then
echo
echo "Please obtain your personal API config from"
echo "https://YOUR_COPR_HOST/api/"
echo "and paste it to the ~/.config/copr"
echo
echo "No API config found at ~/.config/copr"
echo ""
echo "For LOCAL podman-kube testing:"
echo " 1. Run: setup-local-copr"
echo " 2. Get token from: http://localhost:5000/api/"
echo " 3. Save to ~/.config/copr"
echo ""
echo "For STAGING testing:"
echo " 1. Get token from: https://copr.stg.fedoraproject.org/api/"
echo " 2. Save to ~/.config/copr"
echo ""
mkdir -p "$HOME/.config"
else
echo
echo "There's $HOME/.config/copr pre-configured, may need edits."
echo "Config found: ~/.config/copr"
grep -E "^copr_url|^username" "$HOME/.config/copr" 2>/dev/null || true
echo ""
fi

echo "There's /etc/dnf/plugins/copr.d/tested-copr.conf, may need manual edits"
echo
echo "DNF copr plugin: /etc/dnf/plugins/copr.d/tested-copr.conf"
grep -E "^hostname|^protocol|^port" /etc/dnf/plugins/copr.d/tested-copr.conf || true
echo ""
echo "Commands: setup-local-copr, copr-cli whoami"
echo "Tests: cd /root/copr/beaker-tests/Sanity/copr-cli-basic-operations"
echo ""

# most of the time we want to be in this directory
cd /root/copr/beaker-tests/Sanity/copr-cli-basic-operations || :
60 changes: 60 additions & 0 deletions beaker-tests/DockerTestEnv/setup-local-copr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
# Setup test environment for COPR instance
#
# Usage:
# setup-local-copr # Local instance (default)
# setup-local-copr staging # Fedora staging
# setup-local-copr prod # Fedora production

set -e

TARGET="${1:-local}"

case "$TARGET" in
local)
echo "Configuring for local COPR instance..."
HOSTNAME="frontend"
PROTOCOL="http"
PORT="5000"
COPR_URL="http://frontend:5000"
;;
staging|stg)
echo "Configuring for Fedora COPR staging..."
HOSTNAME="copr.stg.fedoraproject.org"
PROTOCOL="https"
PORT="443"
COPR_URL="https://copr.stg.fedoraproject.org"
;;
prod|production)
echo "Configuring for Fedora COPR production..."
HOSTNAME="copr.fedorainfracloud.org"
PROTOCOL="https"
PORT="443"
COPR_URL="https://copr.fedorainfracloud.org"
;;
*)
echo "Unknown target: $TARGET"
echo "Usage: $0 [local|staging|prod]"
exit 1
;;
esac

# Configure DNF copr plugin
cat > /etc/dnf/plugins/copr.d/tested-copr.conf << EOF
[tested-copr]
hostname = $HOSTNAME
protocol = $PROTOCOL
port = $PORT
EOF

echo "DNF copr plugin configured:"
cat /etc/dnf/plugins/copr.d/tested-copr.conf
echo ""

echo "=============================================="
echo "Get your API token from: $COPR_URL/api/"
echo ""
echo "Save to ~/.config/copr with copr_url = $COPR_URL"
echo ""
echo "Test with: copr-cli whoami"
echo "=============================================="
2 changes: 1 addition & 1 deletion beaker-tests/Sanity/copr-cli-basic-operations/helpers
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ setup_checks()
*copr.stg.fedoraproject.org) ;;
*dev-copr.devel.redhat.com) ;;
# https://docs.pagure.org/copr.copr/sanity_tests.html#sanity-tests
*frontend) ;;
*frontend*) ;;
*) rlDie "improper copr_url in $_config" ;;
esac

Expand Down
58 changes: 58 additions & 0 deletions podman-kube/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Run Copr infra with podman kube play

Run COPR infrastructure locally using `podman kube play` with Kubernetes manifests.

## Quick Start

```bash
just up # Start with dev packages
just up-local # Start with local source code mounted
```

## Usage

```bash
just help # Show all commands
```

## Modes

| Mode | Command | Description |
| --------- | -------------------- | --------------------------------------- |
| `dev` | `just up` | Uses `@copr/copr-dev` packages (main) |
| `release` | `just build release` | Uses Fedora packages only |
| `local` | `just up-local` | Mounts repo source code for development |

### Local Development

```bash
just up-local # Start with source mounted at /opt/copr
vim ../frontend/coprs_frontend/ # Edit code
just restart frontend # Pick up changes
```

## Access Points

| Service | URL |
| --------------- | --------------------- |
| Frontend | http://localhost:5000 |
| DistGit | http://localhost:5001 |
| Backend Results | http://localhost:5002 |
| Resalloc WebUI | http://localhost:5005 |
| Database | localhost:5009 |

## Host Entries (optional)

Add to `/etc/hosts` for internal URL resolution:

```
127.0.0.1 frontend backend-httpd distgit keygen resalloc
```

## Future: OpenShift Deployment

This podman-kube setup is designed to be portable to OpenShift:

- Kubernetes manifests are compatible with OpenShift
- Container images use standard patterns
- Secrets and ConfigMaps can be managed separately
20 changes: 20 additions & 0 deletions podman-kube/containers/backend-httpd/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM copr-base:latest

LABEL description="COPR Backend HTTPD - serves build results"

RUN --mount=type=cache,target=/var/cache/dnf \
dnf -y install nginx && \
dnf clean all

COPY files/nginx.conf /etc/nginx/nginx.conf

RUN mkdir -p /var/lib/copr/public_html/results && \
chown -R nginx:nginx /var/lib/copr /var/log/nginx /var/run

USER nginx
EXPOSE 5002
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
CMD curl -sf http://localhost:5002/ || exit 1

ENTRYPOINT []
CMD ["nginx", "-g", "daemon off;"]
60 changes: 60 additions & 0 deletions podman-kube/containers/backend-httpd/files/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# COPR Backend HTTP server for serving build results

worker_processes auto;
error_log /dev/stderr;
pid /tmp/nginx.pid;

events {
worker_connections 1024;
}

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

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

access_log /dev/stdout main;
sendfile on;
keepalive_timeout 65;

server {
listen 5002;
listen [::]:5002;
server_tokens off;
server_name localhost;
charset utf-8;

root /var/lib/copr/public_html/;
default_type text/plain;

location / {
port_in_redirect off;
autoindex on;
}

# Serve .log.gz files with proper content-encoding
location ~* \.log\.gz$ {
add_header Content-Encoding gzip;
add_header Content-Type "text/plain; charset=utf-8";
}

# Other .gz files
location ~* \.gz$ {
add_header Content-Encoding gzip;
}

# Disable caching for repomd.xml
location ~* /repomd\.xml$ {
add_header Cache-Control "no-cache";
}

# Disable caching for .log files
location ~* \.log$ {
add_header Cache-Control "no-store";
default_type "text/plain; charset=utf-8";
}
}
}
Loading