Skip to content

Commit

Permalink
fix: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed May 16, 2023
1 parent ef8c8c4 commit 4c533f0
Show file tree
Hide file tree
Showing 27 changed files with 143 additions and 40 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/workflow.build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,27 @@ jobs:
with:
sarif_file: trivy-results.sarif
integration_test:
name: Integration test
name: Tests
needs:
- Build
runs-on: ubuntu-latest
steps:
- uses: "actions/checkout@v3"
- run: yarn --immutable
- run: yarn workspace ${{ inputs.name }} build
# - run: yarn workspace ${{ inputs.name }} build
# env:
# SG_DOCKER_IMAGE: ghcr.io/socialgouv/docker/${{ inputs.name }}:sha-${{ github.sha }}
- run: yarn workspace ${{ inputs.name }} test
env:
SG_DOCKER_IMAGE: ghcr.io/socialgouv/docker/${{ inputs.name }}:sha-${{ github.sha }}

# structure_test:
# name: Structure test
# needs:
# - Build
# runs-on: ubuntu-latest
# steps:
# - uses: brpaz/structure-tests-action@v1
# with:
# image: ghcr.io/socialgouv/docker/${{ inputs.name }}:sha-${{ github.sha }}
# configFile: ${{ inputs.name }}/tests/container-structure-test.yml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ node_modules
!.yarn/releases
!.yarn/sdks
!.yarn/versions

/.bin
24 changes: 24 additions & 0 deletions .scripts/container-structure-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

export PROJECT_CWD=${PROJECT_CWD:-$PWD}

structureTestVersion="1.11.0"
if [ "$(uname)" == "Darwin" ]; then
binFilename="container-structure-test-darwin-amd64"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
binFilename="container-structure-test-linux-amd64"
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
binFilename="container-structure-test-windows-amd64.exe"
fi
if [ ! -d ".bin" ]; then
mkdir -p .bin
fi
export PATH="$PATH:$PROJECT_CWD/.bin"

if ! which container-structure-test; then
curl -L -o .bin/container-structure-test "https://storage.googleapis.com/container-structure-test/v${structureTestVersion}/${binFilename}"
chmod +x .bin/container-structure-test
fi


exec container-structure-test $@
File renamed without changes.
6 changes: 4 additions & 2 deletions bats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"name": "bats",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_bats .",
"test": "$(yarn bin:bats) tests/*"
"build": "docker build -t ${SG_DOCKER_IMAGE:-'socialgouv_docker_bats'} .",
"test": "yarn test:e2e && yarn test:structure",
"test:e2e": "$(yarn bin:bats) tests/*",
"test:structure": "$(yarn bin:container-structure-test) test --image ${SG_DOCKER_IMAGE:-'socialgouv_docker_bats'} --config tests/container-structure-test.yml -v debug"
},
"private": true
}
2 changes: 1 addition & 1 deletion cnpg-pgvector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "cnpg-pgvector",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_cnpg-pgvector .",
"build": "docker build -t ${SG_DOCKER_IMAGE:-'socialgouv_docker_cnpg-pgvector'} .",
"test": "echo no tests to run"
},
"private": true
Expand Down
2 changes: 1 addition & 1 deletion datasette/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "datasette",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_datasette .",
"build": "docker build -t ${SG_DOCKER_IMAGE:-'socialgouv_docker_datasette'} .",
"test": "echo no tests to run"
},
"private": true
Expand Down
2 changes: 1 addition & 1 deletion git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "git",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_git .",
"build": "docker build -t ${SG_DOCKER_IMAGE:-'socialgouv_docker_git'} .",
"test": "echo no tests to run"
},
"private": true
Expand Down
6 changes: 4 additions & 2 deletions nginx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"name": "nginx",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_nginx .",
"test": "$(yarn bin:bats) tests/*"
"build": "docker build -t ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'} .",
"test": "yarn test:e2e && yarn test:structure",
"test:e2e": "$(yarn bin:bats) tests/*",
"test:structure": "$(yarn bin:container-structure-test) test --image ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'} --config tests/container-structure-test.yml -v debug"
},
"private": true
}
4 changes: 2 additions & 2 deletions nginx/tests/404.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ setup_file() {
--rm \
--volume ${BATS_TEST_DIRNAME}/fixtures:/usr/share/nginx/html \
--name socialgouv_docker_nginx \
socialgouv_docker_nginx
${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'}
}

teardown_file() {
docker rm -f socialgouv_docker_nginx
docker rm -f ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'}
}

@test "nginx: should return status 404 (not a SPA)" {
Expand Down
4 changes: 2 additions & 2 deletions nginx/tests/basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
load '../../.bats/common.bats.bash'

setup_file() {
docker run --rm -d -p 8888:8080 --name socialgouv_docker_nginx socialgouv_docker_nginx
docker run --rm -d -p 8888:8080 --name socialgouv_docker_nginx ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'}
}

teardown_file() {
docker rm -f socialgouv_docker_nginx
docker rm -f ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'}
}

@test "nginx: basic nginx should return 'Welcome to nginx!'" {
Expand Down
4 changes: 2 additions & 2 deletions nginx/tests/default-404-2.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ setup_file() {
--rm \
--volume ${BATS_TEST_DIRNAME}/fixtures-404:/usr/share/nginx/html \
--name socialgouv_docker_nginx \
socialgouv_docker_nginx
${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'}
}

teardown_file() {
docker rm -f socialgouv_docker_nginx
docker rm -f ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'}
}

@test "nginx: should return 404 page for next.js exports (not a SPA)" {
Expand Down
4 changes: 2 additions & 2 deletions nginx/tests/default-404.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ setup_file() {
--rm \
--volume ${BATS_TEST_DIRNAME}/fixtures-simple:/usr/share/nginx/html \
--name socialgouv_docker_nginx \
socialgouv_docker_nginx
${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'}
}

teardown_file() {
docker rm -f socialgouv_docker_nginx
docker rm -f ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'}
}

@test "nginx: should return default SocialGouv 404 page (not a SPA)" {
Expand Down
4 changes: 2 additions & 2 deletions nginx/tests/volume.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ setup_file() {
--rm \
--volume ${BATS_TEST_DIRNAME}/fixtures:/usr/share/nginx/html \
--name socialgouv_docker_nginx \
socialgouv_docker_nginx
${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'}
}

teardown_file() {
docker rm -f socialgouv_docker_nginx
docker rm -f ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx'}
}

@test "nginx: with --volume should return 'nginx'" {
Expand Down
6 changes: 4 additions & 2 deletions nginx4spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"name": "nginx4spa",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_nginx4spa .",
"test": "$(yarn bin:bats) tests/*"
"build": "docker build -t ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx4spa'} .",
"test": "yarn test:e2e && yarn test:structure",
"test:e2e": "$(yarn bin:bats) tests/*",
"test:structure": "$(yarn bin:container-structure-test) test --image ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx4spa'} --config tests/container-structure-test.yml -v debug"
},
"private": true
}
23 changes: 23 additions & 0 deletions nginx4spa/pouet.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
23 changes: 23 additions & 0 deletions nginx4spa/pouet.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
4 changes: 2 additions & 2 deletions nginx4spa/tests/404.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
load '../../.bats/common.bats.bash'

setup_file() {
docker run --rm -p 8888:8080 -d --name socialgouv_docker_nginx4spa socialgouv_docker_nginx4spa
docker run --rm -p 8888:8080 -d --name socialgouv_docker_nginx4spa ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx4spa'}
}

teardown_file() {
docker rm -f socialgouv_docker_nginx4spa
docker rm -f ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx4spa'}
}

@test "nginx4spa: should return 200 and homepage on 404 (SPA client-side routing)" {
Expand Down
4 changes: 2 additions & 2 deletions nginx4spa/tests/basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
load '../../.bats/common.bats.bash'

setup_file() {
docker run -p 8888:8080 -d --rm --name socialgouv_docker_nginx4spa socialgouv_docker_nginx4spa
docker run -p 8888:8080 -d --rm --name socialgouv_docker_nginx4spa ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx4spa'}
}

teardown_file() {
docker rm -f socialgouv_docker_nginx4spa
docker rm -f ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx4spa'}
}

@test "nginx4spa: basic nginx should return 'Welcome to nginx!'" {
Expand Down
4 changes: 2 additions & 2 deletions nginx4spa/tests/volume.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ setup_file() {
--rm \
--volume ${BATS_TEST_DIRNAME}/fixtures:/usr/share/nginx/html \
--name socialgouv_docker_nginx4spa \
socialgouv_docker_nginx4spa
${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx4spa'}
}

teardown_file() {
docker rm -f socialgouv_docker_nginx4spa
docker rm -f ${SG_DOCKER_IMAGE:-'socialgouv_docker_nginx4spa'}
}

@test "nginx4spa: with --volume should return 'nginx'" {
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
"lerna": "^6.6.2"
},
"scripts": {
"postversion": "./scripts/push-tags-one-by-one.sh",
"postversion": "./.scripts/push-tags-one-by-one",
"bin:bats": "yarn bin bats",
"bin:container-structure-test": "echo $PROJECT_CWD/.scripts/container-structure-test",
"container-structure-test": "$(yarn bin:container-structure-test)",
"build": "yarn workspaces foreach run build",
"test": "yarn workspaces foreach run test"
"test": "yarn workspaces foreach run test",
"test:e2e": "yarn workspaces foreach run test:e2e",
"test:structure": "yarn workspaces foreach run test:structure"
},
"workspaces": [
"bats",
Expand Down
6 changes: 4 additions & 2 deletions psql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"name": "psql",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_psql .",
"test": "$(yarn bin:bats) tests/*"
"build": "docker build -t ${SG_DOCKER_IMAGE:-'socialgouv_docker_psql'} .",
"test": "yarn test:e2e && yarn test:structure",
"test:e2e": "$(yarn bin:bats) tests/*",
"test:structure": "$(yarn bin:container-structure-test) test --image ${SG_DOCKER_IMAGE:-'socialgouv_docker_psql'} --config tests/container-structure-test.yml -v debug"
},
"private": true
}
2 changes: 1 addition & 1 deletion wait-for-http/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM curlimages/curl:7.86.0@sha256:651d7d471b8d8a36d7872eb4f5132efe84775ca26cafcde3c1a3ad60e7a74dbc
FROM curlimages/curl:7.86.0

COPY ./bin /bin

Expand Down
6 changes: 4 additions & 2 deletions wait-for-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"name": "wait-for-http",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_wait-for-http .",
"test": "$(yarn bin:bats) tests/*"
"build": "docker build -t ${SG_DOCKER_IMAGE:-'socialgouv_docker_wait-for-http'} .",
"test": "yarn test:e2e && yarn test:structure",
"test:e2e": "$(yarn bin:bats) tests/*",
"test:structure": "$(yarn bin:container-structure-test) test --image ${SG_DOCKER_IMAGE:-'socialgouv_docker_wait-for-http'} --config tests/container-structure-test.yml -v debug"
},
"private": true
}
6 changes: 3 additions & 3 deletions wait-for-http/tests/container-structure-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ commandTests:
args: ["--version"]
expectedOutput: ["curl 7\\.\\d+.*"]
- name: "wait-for-http bin"
command: "which"
args: ["wait-for-http"]
expectedOutput: ["/bin/wait-for-http"]
command: "sh"
args: ["/bin/wait-for-http","-V"]
expectedOutput: [".*Ready"]
6 changes: 4 additions & 2 deletions wait-for-postgres/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"name": "wait-for-postgres",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_wait-for-postgres .",
"test": "$(yarn bin:bats) tests/*"
"build": "docker build -t ${SG_DOCKER_IMAGE:-'socialgouv_docker_wait-for-postgres'} .",
"test": "yarn test:e2e && yarn test:structure",
"test:e2e": "$(yarn bin:bats) tests/*",
"test:structure": "$(yarn bin:container-structure-test) test --image ${SG_DOCKER_IMAGE:-'socialgouv_docker_wait-for-postgres'} --config tests/container-structure-test.yml -v debug"
},
"private": true
}
2 changes: 1 addition & 1 deletion wait-for-postgres/tests/wait-for-postgres.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ setup_file() {
}

teardown_file() {
docker rm -f socialgouv_docker_wait-for-postgres_postgres
docker rm -f ${SG_DOCKER_IMAGE:-'socialgouv_docker_wait-for-postgres_postgres'}
}

@test "wait-for-postgres: ensure that a pg is ready" {
Expand Down

0 comments on commit 4c533f0

Please sign in to comment.