Skip to content

Commit f0ed079

Browse files
committed
add video on main dockefiles too
1 parent 81bae3b commit f0ed079

File tree

10 files changed

+142
-65
lines changed

10 files changed

+142
-65
lines changed

.github/workflows/test-unit.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
name: test-unit
22
on: [push]
33
jobs:
4-
test-unit:
4+
test:
55
runs-on: ubuntu-latest
6-
76
steps:
8-
- uses: actions/checkout@v2
9-
- name: install docker compose
10-
run: sudo curl -SL https://github.com/docker/compose/releases/download/v2.27.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
11-
- name: Build and run tests
12-
run: |
13-
docker-compose -f .circleci/compose-unit.yml up -d --wait
14-
timeout 60 bash -c -- 'while [[ "$(docker-compose -f .circleci/compose-unit.yml exec -T rails-unit curl -s -o /dev/null -w ''%{http_code}'' http://localhost:3000/api/v1/health)" != "200" ]]; do sleep 1; printf "."; done'
15-
docker-compose -f .circleci/compose-unit.yml exec -T rails-unit bundle exec rails db:test:prepare
16-
docker-compose -f .circleci/compose-unit.yml exec -T rails-unit bundle exec rspec --format progress
17-
7+
- uses: actions/checkout@v4
8+
- name: compose up
9+
run: |-
10+
PUID="$(id -u)" PGID="$(id -g)" docker compose -f docker-compose.unit.yml up -d --wait --build
11+
- name: show logs
12+
if: failure()
13+
run: |-
14+
docker compose logs rails
15+
- name: start recording
16+
run: |-
17+
docker compose -f docker-compose.unit.yml exec rz curl chromevideo:9494/start
18+
- name: run tests
19+
run: |-
20+
docker compose -f docker-compose.unit.yml exec rz rspec
21+
- name: stop recording
22+
run: |-
23+
docker compose -f docker-compose.unit.yml exec rz curl chromevideo:9494/stop
24+
sleep 3
25+
- uses: actions/upload-artifact@v4
26+
with:
27+
name: test-video
28+
path: vidoutput/out.mp4
29+
if-no-files-found: error

.github/workflows/test.yml

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,27 @@ on: [push]
33
jobs:
44
test:
55
runs-on: ubuntu-latest
6-
services:
7-
postgres:
8-
image: postgres
9-
ports:
10-
- 5432:5432
11-
env:
12-
POSTGRES_PASSWORD: postgres
13-
options: >-
14-
--health-cmd pg_isready
15-
--health-interval 10s
16-
--health-timeout 5s
17-
--health-retries 5
18-
redis:
19-
image: redis
20-
ports:
21-
- 6379:6379
22-
options: --entrypoint redis-server
23-
chrome:
24-
image: selenium/standalone-chrome
25-
ports:
26-
- 4444:4444
27-
28-
container:
29-
image: ruby:3.3-alpine
30-
316
steps:
32-
- uses: actions/checkout@v2
33-
- name: Build and run tests
34-
env:
35-
CHROME_HOSTNAME: chrome
36-
DATABASE_URL: postgres://postgres:postgres@postgres:5432/test
37-
REDIS_URL: redis://redis:6379/0
38-
RAILS_ENV: test
39-
run: |
40-
ruby -v
41-
apk --update add build-base git file less postgresql-dev nodejs tzdata curl rust cargo
42-
gem install bundler
43-
bundle install -j $(nproc) --path vendor
44-
bundle exec rails db:create
45-
bundle exec rails db:migrate
46-
bundle exec rails db:test:prepare
47-
TEST_HOST="$(hostname -i)" bundle exec rspec
7+
- uses: actions/checkout@v4
8+
- name: compose up
9+
run: |-
10+
PUID="$(id -u)" PGID="$(id -g)" docker compose up -d --wait --build
11+
- name: show logs
12+
if: failure()
13+
run: |-
14+
docker compose logs rails
15+
- name: start recording
16+
run: |-
17+
docker compose exec rails curl chromevideo:9494/start
18+
- name: run tests
19+
run: |-
20+
docker compose exec rails rspec
21+
- name: stop recording
22+
run: |-
23+
docker compose exec rails curl chromevideo:9494/stop
24+
sleep 3
25+
- uses: actions/upload-artifact@v4
26+
with:
27+
name: test-video
28+
path: vidoutput/out.mp4
29+
if-no-files-found: error

.gitlab-ci.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,28 @@ test:
3939
- redis:alpine
4040
- postgres:alpine
4141
- selenium/standalone-chrome
42+
- davidsiaw/vrec
4243
variables:
4344
DATABASE_URL: postgres://postgres:postgres@postgres
4445
REDIS_URL: redis://redis:6379/0
4546
CHROME_HOSTNAME: selenium-standalone-chrome
47+
SCREEN_WIDTH: 1280
48+
SCREEN_HEIGHT: 1024
49+
HOST: 'selenium-standalone-chrome:5900'
50+
MP4LOC: '/builds/astrobunny/rails-zen/out.mp4'
51+
GIVEUID: "1000"
52+
GIVEGID: "1000"
4653
script:
4754
- bundle exec rails db:create
4855
- bundle exec rails db:migrate
4956
- bundle exec rails db:test:prepare
5057
- cat /etc/hosts
51-
- echo "$(cat /etc/hosts | grep -Eo "^([0-9\.]+)\s+runner-[0-9a-zA-Z-]{7,8}-+project-[0-9a-zA-Z]+-concurrent-[0-9]+" | grep -Eo "^([0-9\.]+)")" > ip_addr
58+
- echo "$(cat /etc/hosts | grep -Eo "^([0-9\.]+)\s+runner-[0-9a-zA-Z-]+-+project-[0-9a-zA-Z]+-concurrent-[0-9]+" | grep -Eo "^([0-9\.]+)")" > ip_addr
59+
- curl davidsiaw-vrec:9494/start
5260
- TEST_HOST="$(cat ip_addr)" bundle exec rspec
61+
- curl davidsiaw-vrec:9494/stop
62+
- sleep 3
63+
- ls
64+
artifacts:
65+
paths:
66+
- out.mp4

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ RUN apk --update add build-base git file less postgresql-dev nodejs tzdata curl
1212
# git clone https://github.com/rbspy/rbspy && \
1313
# cd rbspy && \
1414
# cargo install && \
15-
mkdir -p /srv/tmp && \
16-
chown -R srv /srv && \
17-
chgrp -R srv /srv
15+
mkdir -p /srv/tmp
1816

1917
ADD Gemfile Gemfile.lock Rakefile package.json .rspec .rubocop.yml .rubocop_todo.yml config.ru /srv/
2018

@@ -32,6 +30,9 @@ ADD --chown=srv:srv config /srv/config
3230
ADD --chown=srv:srv spec /srv/spec
3331
ADD --chown=srv:srv app /srv/app
3432

33+
RUN chown -R srv /srv && \
34+
chgrp -R srv /srv
35+
3536
USER srv
3637

3738
EXPOSE 3000

bin/dbsetup

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
rails db:create
4+
rails db:migrate
5+
rails db:seed
6+
rails db:create RAILS_ENV=test

docker-compose.unit.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ services:
33
rz:
44
build:
55
context: .
6+
args:
7+
PUID: ${PUID}
8+
PGID: ${PGID}
69
dockerfile: docker/unit/Dockerfile
10+
environment:
11+
TEST_HOST: rz
12+
CHROME_HOSTNAME: chrome # Point to the chrome container for testing
713
container_name: rz
814
volumes:
915
- ./docker/unit/postgresql.conf:/srv/postgres/postgresql.conf:ro
@@ -52,12 +58,32 @@ services:
5258
chrome:
5359
image: selenium/standalone-chrome-debug
5460
container_name: chrome
61+
environment:
62+
SCREEN_WIDTH: 1280
63+
SCREEN_HEIGHT: 1024
5564
ports:
5665
- "5900:5900"
5766
healthcheck:
5867
test: ["CMD", "curl", "-v", "http://localhost:4444/wd/hub/status"]
5968
interval: 10s
6069
timeout: 5s
6170
retries: 3
71+
video:
72+
platform: linux/amd64
73+
image: davidsiaw/vrec
74+
container_name: chromevideo
75+
environment:
76+
HOST: 'chrome:5900'
77+
MP4LOC: '/var/output/out.mp4'
78+
GIVEUID: "1000"
79+
GIVEGID: "1000"
80+
ports:
81+
- "9494:9494"
82+
volumes:
83+
- type: bind
84+
source: ./vidoutput
85+
target: /var/output
86+
depends_on:
87+
- chrome
6288
volumes:
6389
db_data:

docker-compose.yml

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ services:
2323
# emails, do periodic checks etc. I recommend using this to your
2424
# advantage to automate schedulable tasks.
2525
sidekiq:
26-
build: .
26+
build:
27+
context: .
28+
args:
29+
PUID: ${PUID}
30+
PGID: ${PGID}
2731
platform: linux/amd64
2832
command: bundle exec sidekiq -C config/sidekiq.yml
2933
environment:
@@ -40,7 +44,11 @@ services:
4044
# Using this mechanism you can also perform database migrations and rollbacks
4145
# docker-compose exec rails rails db:migrate
4246
rails:
43-
build: .
47+
build:
48+
context: .
49+
args:
50+
PUID: ${PUID}
51+
PGID: ${PGID}
4452
platform: linux/amd64
4553
container_name: rails
4654
command: sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
@@ -68,14 +76,18 @@ services:
6876
# This container only starts to prepare the database. It will then exit after it is done.
6977
# Use db/seed.rb to seed your database for development.
7078
rails_startup:
71-
build: .
79+
build:
80+
context: .
81+
args:
82+
PUID: ${PUID}
83+
PGID: ${PGID}
7284
platform: linux/amd64
7385
environment:
7486
DATABASE_URL: postgres://postgres:postgres@db
7587
depends_on:
7688
- db
7789
- redis
78-
command: sh -c "rails db:create && rails db:migrate && rails db:seed"
90+
command: sh bin/dbsetup
7991

8092
# ****************
8193
# Tools
@@ -111,13 +123,33 @@ services:
111123
platform: linux/amd64
112124
image: selenium/standalone-chrome-debug
113125
container_name: chrome
126+
environment:
127+
SCREEN_WIDTH: 1280
128+
SCREEN_HEIGHT: 1024
114129
ports:
115130
- "5900:5900"
116131
healthcheck:
117132
test: ["CMD", "curl", "-vf", "http://localhost:4444/wd/hub/status"]
118133
interval: 10s
119134
timeout: 5s
120135
retries: 3
136+
video:
137+
platform: linux/amd64
138+
image: davidsiaw/vrec
139+
container_name: chromevideo
140+
environment:
141+
HOST: 'chrome:5900'
142+
MP4LOC: '/var/output/out.mp4'
143+
GIVEUID: "1000"
144+
GIVEGID: "1000"
145+
ports:
146+
- "9494:9494"
147+
volumes:
148+
- type: bind
149+
source: ./vidoutput
150+
target: /var/output
151+
depends_on:
152+
- chrome
121153
volumes:
122154
db_data:
123155
active_storage:

docker/unit/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ RUN apk --update add build-base git file less postgresql-dev nodejs tzdata curl
1313
# git clone https://github.com/rbspy/rbspy && \
1414
# cd rbspy && \
1515
# cargo install && \
16-
mkdir -p /srv/tmp && \
17-
chown -R srv /srv
16+
mkdir -p /srv/tmp
1817

1918
ADD Gemfile Gemfile.lock Rakefile package.json .rspec .rubocop.yml .rubocop_todo.yml config.ru /srv/
2019

@@ -34,7 +33,11 @@ ADD --chown=srv:srv app /srv/app
3433

3534
ADD --chown=srv:srv docker/unit/start.sh docker/unit/waitpg.sh docker/unit/waitredis.sh docker/unit/Procfile /srv/
3635

37-
RUN mkdir -p /run/redis && mkdir -p /run/postgresql && chown -R srv:srv /run
36+
RUN mkdir -p /run/redis && \
37+
mkdir -p /run/postgresql && \
38+
chown -R srv:srv /run && \
39+
chown -R srv /srv && \
40+
chgrp -R srv /srv
3841

3942
USER srv
4043

docker/unit/Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
postgres: postgres -D /srv/postgres
22
redis: redis-server
3-
rails: rails assets:precompile; sh waitpg.sh; rails db:create; rails db:migrate; rails db:seed; sh waitredis.sh; bundle exec rails s -b 0.0.0.0 -p 3000
3+
rails: rails assets:precompile; sh waitpg.sh; sh bin/dbsetup; sh waitredis.sh; bundle exec rails s -b 0.0.0.0 -p 3000
44
sidekiq: sh waitpg.sh && sh waitredis.sh && sleep 5 && bundle exec sidekiq -C config/sidekiq.yml

vidoutput/.keep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.keep

0 commit comments

Comments
 (0)