Skip to content

Commit 26ff31f

Browse files
authored
A new and better Docker setup (#95)
* Update Docker file * moar docker * hepp * ignore * clean * rollback * build releases * Use latest major container * remove comments * fixes * more * format * hepp * move config * fix config * new test * fix * test on mac and Windows * fix naming * fixes * hepp * fixes * retries * moar log
1 parent 5fbdb02 commit 26ff31f

18 files changed

+519
-71
lines changed

.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
KEYDB_PASSWORD=jgsay7f2fgfgda6acCa7g()jaba51!
2+
KEYDB_DOCKER_VERSION=latest
23
POSTGRES_USER=sitespeedio
34
POSTGRES_PASSWORD=jhde7gFArda33Saa1!4dd2dagJ
45
POSTGRES_DB=sitespeedio
6+
POSTGRESQL_DOCKER_VERSION=16.2
57
MINIO_ROOT_USER=sitespeedio
68
MINIO_ROOT_PASSWORD=tracksofmytears
9+
MINIO_DOCKER_VERSION=RELEASE.2024-05-10T01-41-38Z
10+
MINIO_MC_DOCKER_VERSION=RELEASE.2024-10-08T09-37-26Z
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build Docker server container on new tag
2+
on:
3+
push:
4+
tags:
5+
- 'server-v*.*.*'
6+
jobs:
7+
docker:
8+
runs-on: ubuntu-latest
9+
steps:
10+
-
11+
name: Checkout
12+
uses: actions/checkout@v4
13+
-
14+
name: Set up QEMU
15+
uses: docker/setup-qemu-action@v3
16+
-
17+
name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v3
19+
-
20+
name: Login to DockerHub
21+
uses: docker/login-action@v3
22+
with:
23+
username: ${{ secrets.DOCKERHUB_USERNAME }}
24+
password: ${{ secrets.DOCKERHUB_TOKEN }}
25+
- name: Extract version
26+
id: extract_version
27+
run: |
28+
VERSION_TAG=${GITHUB_REF#refs/tags/}
29+
echo "Git tag: $VERSION_TAG"
30+
31+
VERSION=${VERSION_TAG#v}
32+
echo "Full version without 'v': $VERSION"
33+
34+
MAJOR_VERSION=${VERSION%%.*}
35+
echo "Major version: $MAJOR_VERSION"
36+
37+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
38+
echo "MAJOR_VERSION=$MAJOR_VERSION" >> $GITHUB_OUTPUT
39+
-
40+
name: Build and push sitespeed.io
41+
uses: docker/build-push-action@v6
42+
with:
43+
context: ./server/
44+
file: ./server/Dockerile
45+
platforms: linux/amd64,linux/arm64
46+
push: true
47+
provenance: false
48+
tags: |
49+
sitespeedio/server:${{steps.extract_version.outputs.VERSION}}
50+
sitespeedio/server:${{steps.extract_version.outputs.MAJOR_VERSION}}
51+
sitespeedio/server:latest
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build Docker testrunner container on new tag
2+
on:
3+
push:
4+
tags:
5+
- 'testrunner-v*.*.*'
6+
jobs:
7+
docker:
8+
runs-on: ubuntu-latest
9+
steps:
10+
-
11+
name: Checkout
12+
uses: actions/checkout@v4
13+
-
14+
name: Set up QEMU
15+
uses: docker/setup-qemu-action@v3
16+
-
17+
name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v3
19+
-
20+
name: Login to DockerHub
21+
uses: docker/login-action@v3
22+
with:
23+
username: ${{ secrets.DOCKERHUB_USERNAME }}
24+
password: ${{ secrets.DOCKERHUB_TOKEN }}
25+
- name: Extract version
26+
id: extract_version
27+
run: |
28+
VERSION_TAG=${GITHUB_REF#refs/tags/}
29+
echo "Git tag: $VERSION_TAG"
30+
31+
VERSION=${VERSION_TAG#v}
32+
echo "Full version without 'v': $VERSION"
33+
34+
MAJOR_VERSION=${VERSION%%.*}
35+
echo "Major version: $MAJOR_VERSION"
36+
37+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
38+
echo "MAJOR_VERSION=$MAJOR_VERSION" >> $GITHUB_OUTPUT
39+
-
40+
name: Build and push sitespeed.io
41+
uses: docker/build-push-action@v6
42+
with:
43+
context: ./testrunner/
44+
file: ./testrunner/Dockerile
45+
platforms: linux/amd64,linux/arm64
46+
push: true
47+
provenance: false
48+
tags: |
49+
sitespeedio/testrunner:${{steps.extract_version.outputs.VERSION}}
50+
sitespeedio/testrunner:${{steps.extract_version.outputs.MAJOR_VERSION}}
51+
sitespeedio/testrunner:latest
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Test running everything in Docker using Linux
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Use Node.js
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: '20.x'
17+
- uses: actions/checkout@v4
18+
- name: Start dependencies
19+
run: docker compose -f docker-compose.yml -f docker-compose-local.yml up -d
20+
- name: Show versions
21+
run: |
22+
docker --version
23+
docker network ls
24+
docker network inspect skynet
25+
- name: Get host IP
26+
run: echo "HOST_IP=$(hostname -I | awk '{print $1}')" >> $GITHUB_ENV
27+
- name: Run a test
28+
run: |
29+
git clone https://github.com/sitespeedio/sitespeed.io.git
30+
cd sitespeed.io
31+
npm install
32+
bin/sitespeed.js https://www.wikipedia.org -n 1 --api.hostname 127.0.0.1 --api.location docker --headless --api.json --s3.endpoint "http://${{ env.HOST_IP }}:9000"
33+
- name: Display Server log
34+
if: failure() || success()
35+
run: docker logs onlinetest-sitespeed.io-server-1
36+
- name: Display testrunner log
37+
if: failure() || success()
38+
run: docker logs onlinetest-sitespeed.io-testrunner-1

docker-compose-local.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
services:
2+
sitespeed.io-server:
3+
image: sitespeedio/server:latest
4+
environment:
5+
redis_host: keydb
6+
redis_port: 6379
7+
redis_password: ${KEYDB_PASSWORD}
8+
database_user: ${POSTGRES_USER}
9+
database_server: postgresql
10+
database_name: sitespeedio
11+
database_password: ${POSTGRES_PASSWORD}
12+
database_port: 5432
13+
ports:
14+
- "3000:3000"
15+
networks:
16+
- skynet
17+
depends_on:
18+
- keydb
19+
- postgresql
20+
- minio
21+
sitespeed.io-testrunner:
22+
image: sitespeedio/testrunner:latest
23+
environment:
24+
redis_host: keydb
25+
redis_port: 6379
26+
redis_password: ${KEYDB_PASSWORD}
27+
docker_extraparameters: '--cap-add=NET_ADMIN --network=skynet'
28+
sitespeed.io_s3_endpoint: "http://minio:9000"
29+
sitespeed.io_s3_bucketname: 'sitespeedio'
30+
sitespeed.io_s3_key: 'sitespeedio'
31+
sitespeed.io_s3_secret: "tracksofmytears"
32+
sitespeed.io_s3_region: "motown"
33+
sitespeed.io_s3_options_forcePathStyle: true
34+
sitespeed.io_s3_removeLocalResult: true
35+
sitespeed.io_resultBaseURL: "http://127.0.0.1:9000/sitespeedio"
36+
volumes:
37+
- /var/run/docker.sock:/var/run/docker.sock
38+
- /tmp:/tmp
39+
cap_add:
40+
- NET_ADMIN
41+
depends_on:
42+
- keydb
43+
- minio
44+
- sitespeed.io-server
45+
networks:
46+
- skynet

docker-compose.yml

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,61 @@
11
services:
2-
keydb:
3-
image: eqalpha/keydb:latest
4-
hostname: keydb
5-
ports:
6-
- "6379:6379"
7-
command: ["keydb-server", "/etc/keydb/keydb.conf", "--server-threads" , "2"]
8-
restart: always
9-
volumes:
10-
- keydb_data:/data
11-
- ./keydb.conf:/etc/keydb/keydb.conf
12-
postgresql:
13-
image: postgres:16.2
14-
hostname: postgresql
15-
ports:
16-
- "5432:5432"
17-
environment:
18-
- POSTGRES_USER=${POSTGRES_USER}
19-
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
20-
- POSTGRES_DB=sitespeedio
21-
volumes:
22-
- ./server/database/setup/:/docker-entrypoint-initdb.d
23-
- postgres-data:/var/lib/postgresql/data
24-
minio:
25-
image: minio/minio:RELEASE.2024-05-10T01-41-38Z
26-
volumes:
27-
- minio-data:/data
28-
ports:
29-
- "9000:9000"
30-
- "9001:9001"
31-
environment:
32-
- MINIO_ROOT_USER=${MINIO_ROOT_USER}
33-
- MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD}
34-
command: server /data --console-address ":9001"
35-
mc:
36-
image: minio/mc:RELEASE.2024-05-09T17-04-24Z
37-
depends_on:
38-
- minio
39-
entrypoint: >
40-
/bin/sh -c "
41-
/usr/bin/mc alias set sitespeedio http://minio:9000 sitespeedio tracksofmytears &&
42-
(/usr/bin/mc mb --region --region=motown sitespeedio/sitespeedio || echo 'Bucket already exists') &&
43-
/usr/bin/mc ilm rule add --expire-days 30 sitespeedio/sitespeedio &&
44-
/usr/bin/mc anonymous set public myminio/sitespeedio &&
45-
/usr/bin/mc admin config set sitespeedio compression extensions=".html,.css,.js" &&
46-
echo 'MinIO and lifecycle policy setup complete.'"
47-
environment:
48-
MC_HOST_myminio: http://sitespeedio:tracksofmytears@minio:9000
2+
keydb:
3+
image: eqalpha/keydb:${KEYDB_DOCKER_VERSION}
4+
hostname: keydb
5+
ports:
6+
- "6379:6379"
7+
command: ["keydb-server", "/etc/keydb/keydb.conf", "--server-threads" , "2"]
8+
restart: always
9+
networks:
10+
- skynet
11+
volumes:
12+
- keydb_data:/data
13+
- ./keydb.conf:/etc/keydb/keydb.conf
14+
postgresql:
15+
image: postgres:${POSTGRESQL_DOCKER_VERSION}
16+
hostname: postgresql
17+
ports:
18+
- "5432:5432"
19+
networks:
20+
- skynet
21+
environment:
22+
- POSTGRES_USER=${POSTGRES_USER}
23+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
24+
- POSTGRES_DB=sitespeedio
25+
volumes:
26+
- ./server/database/setup/:/docker-entrypoint-initdb.d
27+
- postgres-data:/var/lib/postgresql/data
28+
minio:
29+
image: minio/minio:${MINIO_DOCKER_VERSION}
30+
volumes:
31+
- minio-data:/data
32+
ports:
33+
- "9000:9000"
34+
environment:
35+
- MINIO_ROOT_USER=${MINIO_ROOT_USER}
36+
- MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD}
37+
command: server /data --console-address ":9001"
38+
networks:
39+
- skynet
40+
mc:
41+
image: minio/mc:${MINIO_MC_DOCKER_VERSION}
42+
depends_on:
43+
- minio
44+
networks:
45+
- skynet
46+
entrypoint: >
47+
/bin/sh -c "
48+
/usr/bin/mc alias set sitespeedio http://minio:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD} &&
49+
(/usr/bin/mc mb --region=motown sitespeedio/sitespeedio || echo 'Bucket already exists') &&
50+
/usr/bin/mc ilm rule add --expire-days 30 sitespeedio/sitespeedio &&
51+
/usr/bin/mc anonymous set public sitespeedio/sitespeedio &&
52+
/usr/bin/mc admin config set sitespeedio compression extensions=\".html,.css,.js\" &&
53+
echo 'MinIO and lifecycle policy setup complete.'"
4954
volumes:
5055
postgres-data:
5156
minio-data:
5257
keydb_data:
53-
driver: local
58+
driver: local
59+
networks:
60+
skynet:
61+
name: skynet

server/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ WORKDIR /usr/src/app
44

55
COPY package.json npm-shrinkwrap.json ./
66

7-
RUN npm ci --omit=dev
7+
RUN npm ci --omit=dev && npm cache clean --force
88

99
COPY . .
10+
COPY config/default.yaml /usr/src/app/config/default.yaml
1011

1112
RUN useradd --user-group --create-home --shell /bin/false sitespeed && \
1213
chown -R sitespeed:sitespeed /usr/src/app
@@ -16,4 +17,4 @@ USER sitespeed
1617
EXPOSE 3000
1718

1819
ENTRYPOINT ["node", "app.js"]
19-
CMD []
20+
CMD []

server/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const configFile = nconf.get('config')
4141
const fileExtension = extname(configFile).toLowerCase();
4242
let configFromFile;
4343

44+
nconf.env({ parseValues: true, separator: '_' });
45+
4446
try {
4547
const fileContent = fs.readFileSync(configFile, 'utf8');
4648
if (fileExtension === '.json') {

server/config/default.yaml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ redis:
1515
# Configure the postgresql database
1616
database:
1717
user: sitespeedio
18-
server: localhost
18+
server: 127.0.0.1
1919
name: sitespeedio
2020
password: jhde7gFArda33Saa1!4dd2dagJ
2121
port: 5432
@@ -87,9 +87,6 @@ admin:
8787
basicAuth:
8888
login: appojke
8989
password: monkeyboy
90-
91-
# The default sitspeed.io configuration file that will be merged to all tests.
92-
# defaultSitespeedioConfigFile:
9390

9491
# The number of jobs to keep in the queue
9592
# Depending on how many jobs you run and how much memory
@@ -98,12 +95,10 @@ queue:
9895
removeOnComplete: 50
9996
removeOnFail: 50
10097

101-
sitespeed.io:
102-
s3:
103-
endpoint: "http://127.0.0.1:9000"
104-
bucketname: "sitespeedio"
105-
key: "sitespeedio"
106-
secret: "tracksofmytears"
107-
region: "motown"
108-
109-
resultBaseURL: "http://127.0.0.1:9000/sitespeedio"
98+
99+
# The default sitspeed.io configuration file that will be merged to all tests.
100+
# defaultSitespeedioConfigFile:
101+
102+
# If you don't setup a default sitespeed.io configuration, you can add
103+
# your sitespeed.io configuration directly in this block
104+
sitespeed.io:

0 commit comments

Comments
 (0)