Skip to content

Windows container support #22

Closed
Closed
@gerneio

Description

@gerneio

Put together the below dockerfile and powershell run script that should work if you want to run the email proxy as a windows container (python running on windowservercore in this case).

Didn't want to submit a pull request since I wasn't sure if 1) you wanted this repo to directly support and push out support for windows containers, and 2) wasn't sure how you'd want to configure it and with all that auto-build pipeline stuff. So just leaving this here in case you or someone else want to utilize it.

For me, it's a tad bit slow getting started compared to the alpine container, which is to be expected, but it does seem to work!

For the most part, the docker run or compose commands remained the same, with the exception of how you map the volumes -v C:\path\to\host\config:C:\config since it's specific to windows.

dockerfile
# Use a Python image based on windowsservercore
FROM python:3

# Set the working directory
WORKDIR /app


# Install core dependencies
RUN pip install --no-cache-dir \
    cryptography \
    pyasyncore \
    boto3 \
    prompt_toolkit \
    emailproxy

# Copy the Python script and powershell script into the container
COPY run_email_proxy.ps1 /app/

# Run the shell script
CMD "powershell -c .\run_email_proxy.ps1"
run_email_proxy.ps1 (translated run_email_proxy.sh mostly w/ chat gpt)
# Set default values for external_auth, local_auth, debug, cache_store, and logfile
$EXTERNAL_AUTH_VALUE = ""
$LOCAL_SERVER_AUTH_VALUE = ""
$DEBUG_VALUE = ""
$CACHE_STORE_VALUE = ""
$LOG_FILE_PATH = ""

# Check if LOCAL_SERVER_AUTH environment variable is set to "true"
if ($env:LOCAL_SERVER_AUTH -eq "true") {
    $LOCAL_SERVER_AUTH_VALUE = "--local-server-auth"
} else {
    $EXTERNAL_AUTH_VALUE = "--external-auth"  # Default to --external-auth if not using local server auth
}

# Check if DEBUG environment variable is set to "true"
if ($env:DEBUG -eq "true") {
    $DEBUG_VALUE = "--debug"
}

# Check if CACHE_STORE environment variable is set
if ($env:CACHE_STORE) {
    $CACHE_STORE_VALUE = "--cache-store $($env:CACHE_STORE)"
}

# Check if LOGFILE environment variable is set to "true"
if ($env:LOGFILE -eq "true") {
    $LOG_FILE_PATH = "/config/emailproxy.log"
} else {
    $LOG_FILE_PATH = "/app/emailproxy.log"
}

# Build the argument list
$arguments = @("-m emailproxy", "--no-gui", "--config-file", "/config/emailproxy.config")

if ($LOG_FILE_PATH) {
    $arguments += "--log-file"
    $arguments += $LOG_FILE_PATH
}

if ($CACHE_STORE_VALUE) { $arguments += $CACHE_STORE_VALUE }
if ($DEBUG_VALUE) { $arguments += $DEBUG_VALUE }
if ($EXTERNAL_AUTH_VALUE) { $arguments += $EXTERNAL_AUTH_VALUE }
if ($LOCAL_SERVER_AUTH_VALUE) { $arguments += $LOCAL_SERVER_AUTH_VALUE }

Write-Output "Starting emailproxy..."

# Execute the Python script with arguments
Start-Process -NoNewWindow python -ArgumentList $arguments

# Wait for the log file to be created
while (-not (Test-Path $LOG_FILE_PATH)) {
    Start-Sleep -Seconds 1
}

# Stream the log file to Docker logs or a specified file
Get-Content -Path $LOG_FILE_PATH -Wait

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions