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 830357a commit ef35385
Show file tree
Hide file tree
Showing 33 changed files with 179 additions and 61 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/workflow.build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,5 @@ jobs:
steps:
- uses: "actions/checkout@v3"
- run: yarn --immutable
- run: |
if [ -d tests ]; then
$(yarn workspace root bin bats) tests/*
fi
working-directory: ${{ inputs.name }}
- run: yarn workspace ${{ inputs.name }} build
- run: yarn workspace ${{ inputs.name }} test
28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.5.1.cjs
54 changes: 27 additions & 27 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,41 @@

We use nodejs tools to help developing, testing the images.

### install

```sh
yarn
```

### build

#### one image
```sh
# Install all with
$ yarn
yarn workspace <package> build
```

**NOTE**: You might need to manualy install `dhall` and `postgres-client` on your computeur for now...
#### all images
```sh
yarn build
```

### test

you must build image before running tests on it

We use `Makefile` to orchestrator the monorepo.
#### one image

```sh
$ cd <package>
$ make
# Will deal with one package build and tests
yarn workspace <package> test
```

#### all images

```sh
yarn workspace test
```


## Create a new image

1. Create a folder with the image name (example: foo)
Expand All @@ -32,21 +52,8 @@ $ mkdir foo
You can follow the [`wait-for-postgres/README.md` as model](./wait-for-postgres/README.md).
1. Add the image to the table in the [root `README.md`](./README.md).
Keep alpha sorted plz ;)
1. Add a `Makefile` to specify how to make the image
You can follow the [`wait-for-postgres/Makefile` as model](./wait-for-postgres/Makefile).
1. Add a `Makefile` to specify how to make the image
You can follow the [`wait-for-postgres/Makefile` as model](./wait-for-postgres/Makefile).
1. Add a `docker-compose.yml` with a `.env` handle docker configurations
We name the service with the distro used as from for the image
You can follow the [`wait-for-postgres/docker-compose.yml` as model](./wait-for-postgres/docker-compose.yml) and[`wait-for-postgres/.env` as model](./wait-for-postgres/.env).
Note that there is an additional service `postgres` used for tests here
1. Add [container structure test](https://github.com/GoogleContainerTools/container-structure-test/)
We ensure that the built image is well made :)
You can follow the [`wait-for-postgres/tests/container-structure-test.yml` as model](./wait-for-postgres/tests/container-structure-test.yml)
1. Add [bats](https://github.com/bats-core/bats-core) integration test
Additional config and binaries can be tested with bats files in the `tests` folder
You can follow the [`wait-for-postgres/docker-compose.yml` as model](./wait-for-postgres/docker-compose.yml) and[`wait-for-postgres/.env` as model](./wait-for-postgres/.env).
Note that there is an additional service `postgres` used for tests here

## Test

Expand All @@ -57,10 +64,3 @@ $ docker run --rm -i ghcr.io/hadolint/hadolint < ./<image>/Dockerfile
# example
$ docker run --rm -i ghcr.io/hadolint/hadolint < ./helm/Dockerfile
```

## Generate GitHub Workflow

## Release policy

We mainly use [semantic-release](https://github.com/semantic-release/semantic-release) to generate our release
You need an [Github token](https://github.com/settings/tokens/new) to release.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ $ docker pull ghcr.io/socialgouv/docker/<image>
| --------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| **bats** | `docker pull ghcr.io/socialgouv/docker/bats` | [![README](https://img.shields.io/badge/README--green.svg)](./bats/README.md) |
| **cnpg-pgvector** | `docker pull ghcr.io/socialgouv/docker/cnpg-pgvector` | [![README](https://img.shields.io/badge/README--green.svg)](./cnpg-pgvector/README.md) |
| **datasette** | `docker pull ghcr.io/socialgouv/docker/datasette` | [![README](https://img.shields.io/badge/README--green.svg)](./datasette/README.md) |
| **git** | `docker pull ghcr.io/socialgouv/docker/git` | [![README](https://img.shields.io/badge/README--green.svg)](./git/README.md) |
| **nginx** | `docker pull ghcr.io/socialgouv/docker/nginx` | [![README](https://img.shields.io/badge/README--green.svg)](./nginx/README.md) |
| **nginx4spa** | `docker pull ghcr.io/socialgouv/docker/nginx4spa` | [![README](https://img.shields.io/badge/README--green.svg)](./nginx4spa/README.md) |
| **psql** | `docker pull ghcr.io/socialgouv/docker/psql` | [![README](https://img.shields.io/badge/README--green.svg)](./psql/README.md) |
Expand Down
4 changes: 4 additions & 0 deletions bats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"version": "7.6.2-alpha.18",
"name": "bats",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_bats .",
"test": "$(yarn bin:bats) tests/*"
},
"private": true
}
4 changes: 4 additions & 0 deletions cnpg-pgvector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"version": "7.6.2-alpha.17",
"name": "cnpg-pgvector",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_cnpg-pgvector .",
"test": "echo no tests to run"
},
"private": true
}
1 change: 1 addition & 0 deletions datasette/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Datasette
4 changes: 4 additions & 0 deletions datasette/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"version": "7.6.2-alpha.16",
"name": "datasette",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_datasette .",
"test": "echo no tests to run"
},
"private": true
}
1 change: 1 addition & 0 deletions git/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Git
4 changes: 4 additions & 0 deletions git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"version": "7.6.2-alpha.16",
"name": "git",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_git .",
"test": "echo no tests to run"
},
"private": true
}
1 change: 0 additions & 1 deletion nginx/.env

This file was deleted.

4 changes: 4 additions & 0 deletions nginx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"version": "7.6.2-alpha.17",
"name": "nginx",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_nginx .",
"test": "$(yarn bin:bats) tests/*"
},
"private": true
}
7 changes: 4 additions & 3 deletions nginx/tests/404.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
load '../../.bats/common.bats.bash'

setup_file() {
docker-compose run \
docker run \
--detach \
--publish 8888:8080 \
--rm \
--volume ${BATS_TEST_DIRNAME}/fixtures:/usr/share/nginx/html \
alpine
--name socialgouv_docker_nginx \
socialgouv_docker_nginx
}

teardown_file() {
docker-compose rm -sf
docker rm -f 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-compose up -d alpine
docker run --rm -d -p 8888:8080 --name socialgouv_docker_nginx socialgouv_docker_nginx
}

teardown_file() {
docker-compose stop
docker rm -f socialgouv_docker_nginx
}

@test "nginx: basic nginx should return 'Welcome to nginx!'" {
Expand Down
7 changes: 4 additions & 3 deletions nginx/tests/default-404-2.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
load '../../.bats/common.bats.bash'

setup_file() {
docker-compose run \
docker run \
--detach \
--publish 8888:8080 \
--rm \
--volume ${BATS_TEST_DIRNAME}/fixtures-404:/usr/share/nginx/html \
alpine
--name socialgouv_docker_nginx \
socialgouv_docker_nginx
}

teardown_file() {
docker-compose rm -sf
docker rm -f socialgouv_docker_nginx
}

@test "nginx: should return 404 page for next.js exports (not a SPA)" {
Expand Down
7 changes: 4 additions & 3 deletions nginx/tests/default-404.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
load '../../.bats/common.bats.bash'

setup_file() {
docker-compose run \
docker run \
--detach \
--publish 8888:8080 \
--rm \
--volume ${BATS_TEST_DIRNAME}/fixtures-simple:/usr/share/nginx/html \
alpine
--name socialgouv_docker_nginx \
socialgouv_docker_nginx
}

teardown_file() {
docker-compose rm -sf
docker rm -f socialgouv_docker_nginx
}

@test "nginx: should return default SocialGouv 404 page (not a SPA)" {
Expand Down
7 changes: 4 additions & 3 deletions nginx/tests/volume.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
load '../../.bats/common.bats.bash'

setup_file() {
docker-compose run \
docker run \
--detach \
--publish 8888:8080 \
--rm \
--volume ${BATS_TEST_DIRNAME}/fixtures:/usr/share/nginx/html \
alpine
--name socialgouv_docker_nginx \
socialgouv_docker_nginx
}

teardown_file() {
docker-compose rm -sf
docker rm -f socialgouv_docker_nginx
}

@test "nginx: with --volume should return 'nginx'" {
Expand Down
1 change: 0 additions & 1 deletion nginx4spa/.env

This file was deleted.

4 changes: 4 additions & 0 deletions nginx4spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"version": "7.6.2-alpha.17",
"name": "nginx4spa",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_nginx4spa .",
"test": "$(yarn bin:bats) tests/*"
},
"private": true
}
23 changes: 23 additions & 0 deletions nginx4spa/pouet
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.1
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-compose up -d alpine
docker run --rm -p 8888:8080 -d --name socialgouv_docker_nginx4spa socialgouv_docker_nginx4spa
}

teardown_file() {
docker-compose down
docker rm -f 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-compose up -d alpine
docker run -p 8888:8080 -d --rm --name socialgouv_docker_nginx4spa socialgouv_docker_nginx4spa
}

teardown_file() {
docker-compose stop
docker rm -f socialgouv_docker_nginx4spa
}

@test "nginx4spa: basic nginx should return 'Welcome to nginx!'" {
Expand Down
7 changes: 4 additions & 3 deletions nginx4spa/tests/volume.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
load '../../.bats/common.bats.bash'

setup_file() {
docker-compose run \
docker run \
--detach \
--publish 8888:8080 \
--rm \
--volume ${BATS_TEST_DIRNAME}/fixtures:/usr/share/nginx/html \
alpine
--name socialgouv_docker_nginx4spa \
socialgouv_docker_nginx4spa
}

teardown_file() {
docker-compose rm -sf
docker rm -f socialgouv_docker_nginx4spa
}

@test "nginx4spa: with --volume should return 'nginx'" {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"lerna": "^6.6.2"
},
"scripts": {
"postversion": "./scripts/push-tags-one-by-one.sh"
"postversion": "./scripts/push-tags-one-by-one.sh",
"bin:bats": "yarn bin bats",
"build": "yarn workspaces foreach run build",
"test": "yarn workspaces foreach run test"
},
"workspaces": [
"bats",
Expand Down
1 change: 0 additions & 1 deletion psql/.env

This file was deleted.

4 changes: 4 additions & 0 deletions psql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"version": "7.6.2-alpha.17",
"name": "psql",
"packageManager": "yarn@3.5.1",
"scripts": {
"build": "docker build -t socialgouv_docker_psql .",
"test": "$(yarn bin:bats) tests/*"
},
"private": true
}
1 change: 0 additions & 1 deletion wait-for-http/.env

This file was deleted.

Loading

0 comments on commit ef35385

Please sign in to comment.