Skip to content

Commit

Permalink
Merge pull request #556 from 7flying/db-init
Browse files Browse the repository at this point in the history
feat: add DB initialization module
  • Loading branch information
runcom authored Feb 7, 2024
2 parents da42127 + 530fef0 commit 072e027
Show file tree
Hide file tree
Showing 47 changed files with 3,024 additions and 87 deletions.
6 changes: 5 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
FROM fedora:latest

ENV PATH "$PATH:/home/vscode/.cargo/bin"

RUN bash -c "$(curl -fsSL "https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/common-redhat.sh")" -- "true" "vscode" "1000" "1000" "true"

RUN dnf install -y \
sudo git cargo rust rust-src git-core openssl openssl-devel clippy rustfmt golang tpm2-tss-devel clevis clevis-luks cryptsetup cryptsetup-devel clang-devel \
sudo git cargo rust rust-src git-core openssl openssl-devel clippy rustfmt golang tpm2-tss-devel clevis clevis-luks cryptsetup cryptsetup-devel clang-devel sqlite sqlite-devel libpq libpq-devel \
&& dnf clean all

USER vscode

RUN cargo install --force diesel_cli --no-default-features --features sqlite
12 changes: 12 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
"serayuzgur.crates",
"rust-lang.rust-analyzer"
],
"remoteEnv": {
"PATH": "${containerEnv:PATH}:/home/vscode/.cargo/bin",
"SQLITE_MANUFACTURER_DATABASE_URL": "../ci-manufacturer-db.sqlite",
"SQLITE_OWNER_DATABASE_URL": "../ci-owner-db.sqlite",
"SQLITE_RENDEZVOUS_DATABASE_URL": "../ci-rendezvous-db.sqlite"
},
"containerEnv": {
"SQLITE_MANUFACTURER_DATABASE_URL": "../ci-manufacturer-db.sqlite",
"SQLITE_OWNER_DATABASE_URL": "../ci-owner-db.sqlite",
"SQLITE_RENDEZVOUS_DATABASE_URL": "../ci-rendezvous-db.sqlite"
},
"hostRequirements": {
"memory": "4gb"
},
Expand All @@ -35,5 +46,6 @@
"cargo",
"build"
],
"postCreateCommand": "cargo install --force diesel_cli --no-default-features --features sqlite && diesel migration run --migration-dir ./migrations/migrations_manufacturing_server_sqlite --database-url ./ci-manufacturer-db.sqlite && diesel migration run --migration-dir ./migrations/migrations_owner_onboarding_server_sqlite --database-url ./ci-owner-db.sqlite && diesel migration run --migration-dir ./migrations/migrations_rendezvous_server_sqlite --database-url ./ci-rendezvous-db.sqlite",
"waitFor": "onCreateCommand"
}
35 changes: 32 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
steps:
- name: Install deps
run: |
dnf install -y make gcc openssl openssl-devel findutils golang git tpm2-tss-devel swtpm swtpm-tools git clevis clevis-luks cryptsetup cryptsetup-devel clang-devel cracklib-dicts
dnf install -y make gcc openssl openssl-devel findutils golang git tpm2-tss-devel swtpm swtpm-tools git clevis clevis-luks cryptsetup cryptsetup-devel clang-devel cracklib-dicts sqlite sqlite-devel libpq libpq-devel
- uses: actions/checkout@v3
with:
persist-credentials: false
Expand All @@ -112,7 +112,19 @@ jobs:
env:
FDO_PRIVILEGED: true
PER_DEVICE_SERVICEINFO: false
run: cargo test --workspace
SQLITE_MANUFACTURER_DATABASE_URL: ../ci-manufacturer-db.sqlite
SQLITE_OWNER_DATABASE_URL: ../ci-owner-db.sqlite
SQLITE_RENDEZVOUS_DATABASE_URL: ../ci-rendezvous-db.sqlite
run: |
# prep for database tests
cargo install --force diesel_cli --no-default-features --features sqlite
diesel migration run --migration-dir ./migrations/migrations_manufacturing_server_sqlite --database-url ./ci-manufacturer-db.sqlite
diesel migration run --migration-dir ./migrations/migrations_owner_onboarding_server_sqlite --database-url ./ci-owner-db.sqlite
diesel migration run --migration-dir ./migrations/migrations_rendezvous_server_sqlite --database-url ./ci-rendezvous-db.sqlite
# run tests
cargo test --workspace
# delete sqlite databases
rm -f ./ci-manufacturer-db.sqlite ./ci-owner-db.sqlite ./ci-rendezvous-db.sqlite
- name: Check aio
run: |
mkdir aio-dir/
Expand All @@ -127,6 +139,15 @@ jobs:
run: |
git diff --exit-code
postgres_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run test
run: test/fdo-postgres.sh

commitlint:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -169,4 +190,12 @@ jobs:
- name: Test building in devcontainer
run: docker run --rm -v `pwd`:/code:z --workdir /code --user root devcontainer-fdo-rs cargo build --workspace --verbose
- name: Test testing in devcontainer
run: docker run --rm -v `pwd`:/code:z --workdir /code --user root devcontainer-fdo-rs cargo test --lib --bins --workspace --verbose
run: |
docker run -d -v `pwd`:/code:z --workdir /code --user root -e SQLITE_MANUFACTURER_DATABASE_URL='../ci-manufacturer-db.sqlite' -e SQLITE_OWNER_DATABASE_URL='../ci-owner-db.sqlite' -e SQLITE_RENDEZVOUS_DATABASE_URL='../ci-rendezvous-db.sqlite' --name tests devcontainer-fdo-rs sleep infinity
docker exec --user root tests cargo build --lib --bins --workspace --verbose
docker exec --user root tests diesel migration run --migration-dir ./migrations/migrations_manufacturing_server_sqlite --database-url ./ci-manufacturer-db.sqlite
docker exec --user root tests diesel migration run --migration-dir ./migrations/migrations_owner_onboarding_server_sqlite --database-url ./ci-owner-db.sqlite
docker exec --user root tests diesel migration run --migration-dir ./migrations/migrations_rendezvous_server_sqlite --database-url ./ci-rendezvous-db.sqlite
docker exec --user root tests cargo test
docker stop tests
docker rm tests
102 changes: 102 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"http-wrapper",
"store",
"util",
"db",

"client-linuxapp",
"owner-onboarding-server",
Expand All @@ -24,6 +25,7 @@ default-members = [
"http-wrapper",
"store",
"util",
"db",

"client-linuxapp",
"owner-onboarding-server",
Expand Down
Loading

0 comments on commit 072e027

Please sign in to comment.