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

sqitch docker-sqitch.sh file #22

Open
lastlink opened this issue Nov 4, 2020 · 0 comments
Open

sqitch docker-sqitch.sh file #22

lastlink opened this issue Nov 4, 2020 · 0 comments

Comments

@lastlink
Copy link

lastlink commented Nov 4, 2020

https://github.com/sqitchers/docker-sqitch/blob/main/docker-sqitch.sh

#!/usr/bin/env bash

# Determine which Docker image to run.
SQITCH_IMAGE=${SQITCH_IMAGE:=sqitch/sqitch:latest}

# Set up required pass-through variables.
user=${USER-$(whoami)}
passopt=(
    -e "SQITCH_ORIG_SYSUSER=$user"
    -e "SQITCH_ORIG_EMAIL=$user@$(hostname)"
    -e "TZ=$(date +%Z)" \
    -e "LESS=${LESS:--R}" \
)

# Handle OS-specific options.
case "$(uname -s)" in
    Linux*)
        passopt+=(-e "SQITCH_ORIG_FULLNAME=$(getent passwd $user | cut -d: -f5 | cut -d, -f1)")
        passopt+=(-u $(id -u ${user}):$(id -g ${user}))
        ;;
    Darwin*)
        passopt+=(-e "SQITCH_ORIG_FULLNAME=$(/usr/bin/id -P $user | awk -F '[:]' '{print $8}')")
        ;;
    MINGW*|CYGWIN*)
        passopt+=(-e "SQITCH_ORIG_FULLNAME=$(net user $user)")
        ;;
    *)
        echo "Unknown OS: $(uname -s)"
        exit 2
        ;;
esac

# Iterate over optional Sqitch and engine variables.
for var in \
    SQITCH_CONFIG SQITCH_USERNAME SQITCH_PASSWORD SQITCH_FULLNAME SQITCH_EMAIL SQITCH_TARGET \
    DBI_TRACE \
    PGUSER PGPASSWORD PGHOST PGHOSTADDR PGPORT PGDATABASE PGSERVICE PGOPTIONS PGSSLMODE PGREQUIRESSL PGSSLCOMPRESSION PGREQUIREPEER PGKRBSRVNAME PGKRBSRVNAME PGGSSLIB PGCONNECT_TIMEOUT PGCLIENTENCODING PGTARGETSESSIONATTRS \
    MYSQL_PWD MYSQL_HOST MYSQL_TCP_PORT \
    TNS_ADMIN TWO_TASK ORACLE_SID \
    ISC_USER ISC_PASSWORD \
    VSQL_HOST VSQL_PORT VSQL_USER VSQL_PASSWORD VSQL_SSLMODE \
    SNOWSQL_ACCOUNT SNOWSQL_USER SNOWSQL_PWD SNOWSQL_HOST SNOWSQL_PORT SNOWSQL_DATABASE SNOWSQL_REGION SNOWSQL_WAREHOUSE SNOWSQL_PRIVATE_KEY_PASSPHRASE
do
    if [ -n "${!var}" ]; then
       passopt+=(-e $var)
    fi
done

# Determine the name of the container home directory.
homedst=/home
if [ $(id -u ${user}) -eq 0 ]; then
    homedst=/root
fi
# Set HOME, since the user ID likely won't be the same as for the sqitch user.
passopt+=(-e "HOME=${homedst}")

# Run the container with the current and home directories mounted.
docker run -it --rm --network host \
    --mount "type=bind,src=$(pwd),dst=/repo" \
    --mount "type=bind,src=$HOME,dst=$homedst" \
    "${passopt[@]}" "$SQITCH_IMAGE" "$@"

throws error

parse error: Error: Parse error on line 8: Unexpected 'OPEN_PAREN'

my manual progress so far

@echo off & setlocal EnableDelayedExpansion
setlocal
REM # Determine which Docker image to run.
if "%SQITCH_IMAGE%"=="" (
    set SQITCH_IMAGE=sqitch/sqitch:latest
) 
echo %SQITCH_IMAGE%
REM set SQITCH_IMAGE=sqitch/sqitch:latest

REM # Set up required pass-through variables.
REM set user=whoami
FOR /F "tokens=*" %%g IN ('whoami') do (SET user=%%g)
set passopt= -e "SQITCH_ORIG_SYSUSER=%username%"
FOR /F "tokens=*" %%g IN ('hostname') do (SET machinehostname=%%g)
set passopt=%passopt% -e "SQITCH_ORIG_EMAIL=%username%@%machinehostname%"
FOR /F "tokens=*" %%g IN ('tzutil /g') do (SET TZ=%%g)
set passopt=%passopt% -e "TZ=%TZ%"
if "%LESS%"=="" (
    set LESS=--R
)
if "%LESS%"=="" (
set passopt=%passopt% -e "LESS=%LESS%"

echo %passopt% 

REM # Iterate over optional Sqitch and engine variables.
REM for var in \
REM     SQITCH_CONFIG SQITCH_USERNAME SQITCH_PASSWORD SQITCH_FULLNAME SQITCH_EMAIL SQITCH_TARGET \
REM     DBI_TRACE \
REM     PGUSER PGPASSWORD PGHOST PGHOSTADDR PGPORT PGDATABASE PGSERVICE PGOPTIONS PGSSLMODE PGREQUIRESSL PGSSLCOMPRESSION PGREQUIREPEER PGKRBSRVNAME PGKRBSRVNAME PGGSSLIB PGCONNECT_TIMEOUT PGCLIENTENCODING PGTARGETSESSIONATTRS \
REM     MYSQL_PWD MYSQL_HOST MYSQL_TCP_PORT \
REM     TNS_ADMIN TWO_TASK ORACLE_SID \
REM     ISC_USER ISC_PASSWORD \
REM     VSQL_HOST VSQL_PORT VSQL_USER VSQL_PASSWORD VSQL_SSLMODE \
REM     SNOWSQL_ACCOUNT SNOWSQL_USER SNOWSQL_PWD SNOWSQL_HOST SNOWSQL_PORT SNOWSQL_DATABASE SNOWSQL_REGION SNOWSQL_WAREHOUSE SNOWSQL_PRIVATE_KEY_PASSPHRASE
REM do
REM     if [ -n "${!var}" ]; then
REM        passopt+=(-e $var)
REM     fi
REM done

REM # Determine the name of the container home directory.
set homedst=/home
REM if [ $(id -u ${user}) -eq 0 ]; then
REM     homedst=/root
REM fi
REM # Set HOME, since the user ID likely won't be the same as for the sqitch user.
set passopt=%passopt% -e "HOME=%homedst%"

REM # Run the container with the current and home directories mounted.
docker run -it --rm --network host \
    --mount "type=bind,src=$(pwd),dst=/repo" \
    --mount "type=bind,src=%HOME%,dst=%homedst%" \
    "%passopt%" "%SQITCH_IMAGE%"

echo end
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant