Skip to content

Commit

Permalink
chore: Necessary fixes to earthly book building | NPG-000 (#544)
Browse files Browse the repository at this point in the history
# Description

fix: add rustfmt to run rustdoc-tests.
feat: retry commands in entry scripts up to 6 times

## Type of change

Please delete options that are not relevant.

- [x] Bug fix (non-breaking change which fixes an issue)

## How Has This Been Tested?

- [x] Running `earthly -P ./containers/book+build-docs` locally.

## Checklist

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
  • Loading branch information
saibatizoku authored Aug 30, 2023
1 parent 79165d5 commit b3182ed
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
8 changes: 6 additions & 2 deletions containers/book/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ FROM debian:stable-slim

builder:
FROM ghcr.io/input-output-hk/catalyst-gh-tools:v1.4.3
RUN rustup component add rustfmt

COPY --dir ../..+rust-source/src .
COPY --dir ../..+rust-source/tests .
Expand All @@ -20,6 +21,7 @@ rustdoc-test:
rustdoc:
FROM +builder

BUILD +rustdoc-test
RUN rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu
ENV RUSTDOCFLAGS="$RUSTDOCFLAGS --enable-index-page -Zunstable-options"
RUN cargo +nightly doc \
Expand Down Expand Up @@ -55,7 +57,7 @@ builder-chapter-8:

RUN mkdir /db-diagrams

CMD ["./build-db-diagrams.sh"]
ENTRYPOINT ["./build-db-diagrams.sh"]

# Need to be run with the -P flag
build-chapter-8:
Expand Down Expand Up @@ -93,7 +95,9 @@ mdbook:

# Add an empty '.git' folder, needed by mdbook-open-on-gh for relative path calculation
RUN mkdir .git
CMD while ! mdbook build; do sleep 1; done;
COPY build-mdbook.sh .
RUN chmod ugo+x ./build-mdbook.sh
ENTRYPOINT ["./build-mdbook.sh"]

#RUN mdbook build
SAVE ARTIFACT book
Expand Down
27 changes: 17 additions & 10 deletions containers/book/build-db-diagrams.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
#!/bin/bash
echo "Starting to build Event DB diagrams."
echo "Starting to build EventDB diagrams."
# doc-event-db-setup
echo "Initializing Event DB."
echo "Initializing EventDB."
pushd src/event-db
# [tasks.doc-event-db-init]
while ! psql -e -f setup/setup-db.sql \
# retry up to six times every 5 seconds
if ! (r=6; while ! psql -e -f setup/setup-db.sql \
-v dbName=CatalystEventDocs \
-v dbDescription="Local Docs Catalayst Event DB" \
-v dbDescription="Local Docs Catalayst EventDB" \
-v dbUser="catalyst-event-docs" \
-v dbUserPw="CHANGE_ME" ${@};
do sleep 1;
done;
-v dbUserPw="CHANGE_ME" ${@}; do
((--r))||exit
echo "Failed to initialize EventDB. Retrying."
sleep 5; done;) ; then
echo "EventDB initialization failed."
exit 1;
fi
echo "Initialized EventDB"

# [tasks.run-event-doc-db-migration]
refinery migrate -e DATABASE_URL -c refinery.toml -p ./migrations


## Build the Event DB Documentation (Images of Schema)
## Build the EventDB Documentation (Images of Schema)
popd
echo "Building Event DB diagrams."
echo "Building EventDB diagrams."
# [tasks.build-db-docs-overview-diagram]
dbviz -d CatalystEventDocs \
-h postgres \
Expand Down Expand Up @@ -115,4 +122,4 @@ dbviz -d CatalystEventDocs \
moderation \
> /db-diagrams/event-db-moderation.dot

echo "Finished building Event DB diagrams."
echo "Finished building EventDB diagrams."
25 changes: 25 additions & 0 deletions containers/book/build-mdbook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Enable strict mode
set +x
set -o errexit
set -o pipefail
set -o nounset
set -o functrace
set -o errtrace
set -o monitor
set -o posix
shopt -s dotglob

echo ">>> Building mdbook..."
CMD="mdbook build"
# will retry to build 6 times every 5 seconds
if ! (r=6; while ! eval "$CMD" ; do
((--r))||exit
echo "Build failed. Retrying.";
sleep 5;done) ; then
exit 1
fi

echo ">>> Build successful.";
exit 0

0 comments on commit b3182ed

Please sign in to comment.