Skip to content

Added different way to setup docker #18

Added different way to setup docker

Added different way to setup docker #18

Workflow file for this run

name: Testing CI
on:
- pull_request
- push
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node:
- 18
- 20
os:
# - ubuntu-latest
# - windows-latest
- macos-latest
steps:
- uses: actions/checkout@v3
- name: Setup docker (missing on MacOS)
if: runner.os == 'macos'
run: |
brew install docker
brew install docker-compose
mkdir -p ~/.docker/cli-plugins
ln -sfn /usr/local/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose
which dockerd
sudo /usr/local/bin/dockerd --unprivileged
# colima start
# # For testcontainers to find the Colima socket
# # https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running
# sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
# curl -fsSL https://get.docker.com -o get-docker.sh
# sudo sh get-docker.sh
# sudo usermod -aG docker $USER
# sudo chown $USER /var/run/docker.sock
# newgrp docker
# sudo dseditgroup -o edit -a $(whoami) -t user docker
# sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# sudo chmod +x /usr/local/bin/docker-compose
- name: Setup pg (on Windows)
if: runner.os == 'windows'
run: |
echo "unix_socket_directories = ''" >> "$PGDATA/postgresql.conf"
echo "port = 5432" >> "$PGDATA/postgresql.conf"
$PG_BIN = "C:\Program Files\PostgreSQL\14\bin"
$env:PATH = "$PG_BIN;$env:PATH"
Write-Host "PATH=$env:PATH"
pg_ctl start
Start-Sleep -Seconds 15
cd database
bash setup.sh
- name: Setup redis (on Windows)
if: runner.os == 'windows'
run: |
$URL = "https://github.com/redis-windows/redis-windows/releases/download/7.0.14/Redis-7.0.14-Windows-x64-with-Service.tar.gz"
$outputFolder = "C:\redis"
if (-not (Test-Path $outputFolder)) {
New-Item -ItemType Directory -Path $outputFolder | Out-Null
}
Invoke-WebRequest -Uri $URL -OutFile "redis.tar.gz"
tar -xf "redis.tar.gz" -C $outputFolder
$innerFolder = Get-ChildItem -Path $outputFolder | Select-Object -First 1
Move-Item -Path "$outputFolder\$($innerFolder.Name)\*" -Destination $outputFolder -Force
Remove-Item -Path "$outputFolder\$($innerFolder.Name)" -Force
$REDIS_PATH=$outputFolder
Write-Host "REDIS_PATH=$REDIS_PATH"
cd $REDIS_PATH
dir
sc.exe create Redis binpath=C:\redis\RedisService.exe start= auto
net start Redis
- name: Start docker containers
if: runner.os != 'windows'
run: |
docker-compose -f test-docker-compose.yml up -d pg-example redis-example
# sleep 15 # wait for database to be ready
# docker ps
- name: Wait for PostgreSQL to become healthy
run: |
while [[ "$(docker inspect --format='{{.State.Health.Status}}' pg-example)" != "healthy" ]]; do
echo "Waiting for PostgreSQL container to become healthy..."
sleep 5
done
timeout-minutes: 5
- name: Wait for Redis to become healthy
run: |
while [[ "$(docker inspect --format='{{.State.Health.Status}}' redis-example)" != "healthy" ]]; do
echo "Waiting for Redis container to become healthy..."
sleep 5
done
timeout-minutes: 5
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run dotest
env:
MODE: test
- name: Stop containers
run: docker-compose down