Skip to content

Commit

Permalink
Finally works!
Browse files Browse the repository at this point in the history
  • Loading branch information
guaraqe committed Nov 26, 2022
1 parent cf9bfa9 commit 3b34461
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ ease of customization and reproducible deployment.
Docker images produced here should be easy to deploy to cloud services. The
code here uses Fly.io, but it should be simple to adapt to other platforms.

A deployment done for the [Tashkent State Dental Institute](https://tsdi.uz/)
can be found [here](https://tdsi-gnuhealth.fly.dev/).

# Configuring modules

Modules can be defined in the `release.nix` file. The appropriate versions of
Expand Down Expand Up @@ -55,6 +58,16 @@ Make dure the image is in the `fly.toml` configuration file:
image = "registry.fly.io/$APP_NAME:latest"
```

Save this name in the `secrets.json` file:

```json
{
"app_name": "$APP_NAME",
"pgstring": "postgresql://user:password@host:port"
}
```


# Building and deploying

Once more, all commands should be run inside the Nix shell, by running
Expand Down
9 changes: 4 additions & 5 deletions docker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ let
start = pkgs.writeShellScript "start.sh" ''
set -euo pipefail
echo "Exporting variables..."
export TRYTOND_DATABASE__URI=${pgstring}
export TRYTONPASSFILE=/data/passfile
echo "Creating the database if necessary..."
psql $TRYTOND_DATABASE__URI/postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'health'" |
grep -q 1 ||
Expand Down Expand Up @@ -48,7 +44,10 @@ pkgs.dockerTools.buildImage {
config = {
Env = [
"FONTCONFIG_FILE=${pkgs.fontconfig.out}/etc/fonts/fonts.conf"
"PATH=/bin"
"PATH=/bin:$PATH"
"TRYTOND_DATABASE__URI=${pgstring}"
"TRYTONPASSFILE=/data/passfile"
"TRYTOND_WEB__LISTEN=0.0.0.0:8000"
];
Cmd = [ start ];
ExposedPorts = {
Expand Down
27 changes: 20 additions & 7 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
build-trytond:
nix-build release.nix
# Deployment

build-and-load-image:
docker load < $(nix-build docker.nix)

tag-and-push-image APP:
docker tag gnuhealth-nix registry.fly.io/{{APP}}
tag-and-push-image:
docker tag gnuhealth-nix registry.fly.io/$(cat secrets.json | jq -r .app_name)
flyctl auth docker
docker push registry.fly.io/{{APP}}
docker push registry.fly.io/$(cat secrets.json | jq -r .app_name)

deploy:
flyctl deploy --app $(cat secrets.json | jq -r .app_name)

# Debugging

trytond-build:
nix-build release.nix

start-image:
docker run --network="host" gnuhealth-nix

inspect-image:
docker exec -t -i $(docker ps -aq -f ancestor=gnuhealth-nix) /bin/bash

deploy APP:
flyctl deploy --app {{APP}}
stop-image:
docker stop $(docker ps -aq -f ancestor=gnuhealth-nix)
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ mkShell {
bower2nix
just
flyctl
jq
];
}

0 comments on commit 3b34461

Please sign in to comment.