-
-
Notifications
You must be signed in to change notification settings - Fork 202
142 lines (122 loc) · 5.62 KB
/
test-template.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Test
run-name: "Runner (${{ inputs.runner }}) / Node (${{ inputs.node-version }}) / Runtime (${{ inputs.container-runtime }}) / Workspace (${{ inputs.workspace }})"
on:
workflow_call:
inputs:
runner:
required: true
type: string
node-version:
required: true
type: string
container-runtime:
required: true
type: string
workspace:
required: true
type: string
jobs:
test:
name: "Runner (${{ inputs.runner }}) / Node (${{ inputs.node-version }}) / Runtime (${{ inputs.container-runtime }}) / Workspace (${{ inputs.workspace }})"
runs-on: ${{ inputs.runner }}
steps:
- name: Docker rootless setup 1/2
if: ${{ inputs.container-runtime == 'docker-rootless' }}
uses: ScribeMD/[email protected]
- name: Docker rootless setup 2/2
if: ${{ inputs.container-runtime == 'docker-rootless' }}
run: |
sudo rm -rf /var/run/docker.sock
echo "CI_ROOTLESS=true" >> $GITHUB_ENV
- name: Podman setup
if: ${{ inputs.container-runtime == 'podman' }}
run: |
curl -fsSL "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_$(lsb_release -rs)/Release.key" | gpg --dearmor | sudo tee /etc/apt/keyrings/devel_kubic_libcontainers_unstable.gpg > /dev/null
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/devel_kubic_libcontainers_unstable.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_$(lsb_release -rs)/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:unstable.list > /dev/null
sudo apt-get update
sudo apt-get -y install podman
systemctl enable --now --user podman podman.socket
podman info
echo "DOCKER_HOST=unix://${XDG_RUNTIME_DIR}/podman/podman.sock" >> $GITHUB_ENV
echo "CI_ROOTLESS=true" >> $GITHUB_ENV
echo "CI_PODMAN=true" >> $GITHUB_ENV
- name: Colima constraints
if: ${{ inputs.container-runtime == 'colima' && !startsWith(inputs.runner, 'macos') }}
run: |
run: echo "::error::Colima is only supported on macOS"
exit 1
- name: Colima setup
if: ${{ inputs.container-runtime == 'colima' }}
run: |
brew install docker docker-compose colima
colima start --cpu 3 --memory 14 --disk 14 --runtime docker
colima status
colima --version
echo "DOCKER_HOST=unix://${HOME}/.colima/default/docker.sock" >> $GITHUB_ENV
echo "TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock" >> $GITHUB_ENV
echo "NODE_OPTIONS=--dns-result-order=ipv4first" >> $GITHUB_ENV
- name: Rancher Desktop constraints
if: ${{ inputs.container-runtime == 'rancher-desktop' && !startsWith(inputs.runner, 'macos') }}
run: |
run: echo "::error::Rancher Desktop is only supported on macOS"
exit 1
- name: Rancher Desktop setup
if: ${{ inputs.container-runtime == 'rancher-desktop' }}
run: |
brew install docker docker-compose
brew install --cask rancher
TIMEOUT_SECS_CLI_TOOLS=60
TIMEOUT_SECS_USER_SOCKET=300
echo "Open Rancher Desktop app"
open "/Applications/Rancher Desktop.app"
echo "Wait max of ${TIMEOUT_SECS_CLI_TOOLS}s for Rancher Desktop to create CLI tools"
for i in $(seq 1 ${TIMEOUT_SECS_CLI_TOOLS}); do
if [ -e "$HOME/.rd/bin/rdctl" ]; then
echo "Rancher Desktop CLI tools created after ${i}s"
break
fi
sleep 1
done
if [ ! -e "$HOME/.rd/bin/rdctl" ]; then
echo "Rancher Desktop CLI tools not found"
exit 1
fi
echo "Rancher Desktop initialised successfully, now configure the container runtime"
$HOME/.rd/bin/rdctl set \
--container-engine.name=moby \
--application.admin-access=false \
--kubernetes.enabled=false \
--application.start-in-background=true \
--application.path-management-strategy=manual \
--virtual-machine.number-cpus=3 \
--virtual-machine.memory-in-gb=14 \
|| true
echo "Restart Rancher Desktop"
$HOME/.rd/bin/rdctl shutdown
$HOME/.rd/bin/rdctl start
echo "Wait max of ${TIMEOUT_SECS_USER_SOCKET}s for Rancher socket"
for i in $(seq 1 ${TIMEOUT_SECS_USER_SOCKET}); do
if [ -e "$HOME/.rd/docker.sock" ]; then
echo "Rancher Desktop socket created after ${i}s"
break
fi
sleep 1
done
if [ ! -e "$HOME/.rd/docker.sock" ]; then
echo "Rancher Desktop socket not found"
exit 1
fi
echo "{}" > $HOME/.docker/config.json
echo "DOCKER_HOST=unix://${HOME}/.rd/docker.sock" >> $GITHUB_ENV
echo "TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock" >> $GITHUB_ENV
echo "NODE_OPTIONS=--dns-result-order=ipv4first" >> $GITHUB_ENV
- name: Code checkout
uses: actions/checkout@v4
- name: Install NodeJS ${{ inputs.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- name: Install dependencies
run: npm ci --omit=optional
- name: Run tests
run: npm run test:ci -- ${{ inputs.workspace }}