Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.

Dockerize Airseeker #2

Merged
merged 1 commit into from
Apr 4, 2022
Merged

Dockerize Airseeker #2

merged 1 commit into from
Apr 4, 2022

Conversation

amarthadan
Copy link
Contributor

Issue BEC-259

I've decided to use pm2 as process manager, logrotate to rotate logs and cron to start the log rotation.
Only the cron daemon runs under root, both logrotate and pm2 run under non-root user (airseeker).
In main.ts I'm trying to simulate what the application flow will be - 2 different "loops" (data fetching and beacon updates) running indefinitely in some frequency. On interrupt signal, I'm waiting gracefully till the last loops finish instead of killing them forcefully. There's 10s timeout on the pm2 side if they get stuck (that might be set to something higher, not sure how long would one loop takes on average at the moment).

@amarthadan amarthadan self-assigned this Mar 25, 2022
Copy link
Contributor

@Siegrift Siegrift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logrotate to rotate logs and cron to start the log rotation.

I am missing the configuration about how the logs are rotated, can you clarify that in README/code?

On interrupt signal, I'm waiting gracefully till the last loops finish instead of killing them forcefully. There's 10s timeout on the pm2 side if they get stuck (that might be set to something higher, not sure how long would one loop takes on average at the moment).

How will this work in practice? I started the airseeker container docker run api3/airseeker (without any options) and I tried to kill it docker kill --signal=INT sweet_chatterjee but it did nothing. When I did docker kill sweet_chatterjee it killed the container immediatelly. Please add (working) commands for this into package.json.

Also, please update the README.

@@ -0,0 +1 @@
0 2 * * * logrotate -s /app/.pm2/logrotate.status /etc/logrotate.conf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the content of that logrotate.conf file? How do we modify it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to modify it. It's a default file from the logrotate package and the main thing it does is that it is including everything from the '/etc/logrotate.d/ directory where the actual configs are.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh, I am not ure if having an implicit config for this is a good thing. I'd prefer explicit over implicit. Also, the default config seems to have rention policy for 12 days only whic hseems to me like too little.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's 12 weeks, not 12 days, the rotating is happening weekly. But I agree that an explicit one is better, I added it to the repository. But I kept the content the same. Let me know if you agree with that.

@amarthadan
Copy link
Contributor Author

How will this work in practice? I started the airseeker container docker run api3/airseeker (without any options) and I tried to kill it docker kill --signal=INT sweet_chatterjee but it did nothing. When I did docker kill sweet_chatterjee it killed the container immediately.

You're totally right about the signals, I have to rework it a bit. It was working for the interactive mode (with -it) but I haven't tried the stop and kill commands.

src/main.ts Outdated
@@ -1 +1,31 @@
console.log('main process');
const DATA_FETCH_FREQUENCY = 5000;
const BEACON_UPDATE_FREQUENCY = 10000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
const BEACON_UPDATE_FREQUENCY = 10000;
const BEACON_UPDATE_FREQUENCY = 10_000;

I also like appending the unit to the variable name (i.e. _MS) but definitely not super important

ARG build=local

# Environment
FROM node:14.17-alpine3.14 AS environment
Copy link
Member

@andreogle andreogle Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, we aren't restricted to Node v14 as we are with AWS Lambda. Lambda still doesn't support v16 LTS one year after release 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't thought about that but I guess it would be better to stick to v14 for now just to keep the environments the same. Unless we have some reason (like a feature we want to use) to upgrade.

@amarthadan amarthadan force-pushed the dockerization branch 2 times, most recently from fe27d57 to f7ecf1e Compare March 28, 2022 13:56
@amarthadan amarthadan requested a review from Siegrift March 28, 2022 13:56
Base automatically changed from repository-setup to main March 29, 2022 06:13
Copy link
Contributor

@acenolaza acenolaza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

apps: [
{
name: 'airseeker',
script: './dist/src/main.js',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert on pm2 but I found this in the airnode operation package which might be a better alternative. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean calling ts-node? No, it's not. It's basically the same problem we had when we wanted to dockerize Airkeeper. If we would do it with ts-node we would need to include TypeScript in the Docker image and the start would take longer because the source code needs to be transpiled.

@amarthadan amarthadan merged commit 55650ca into main Apr 4, 2022
@amarthadan amarthadan deleted the dockerization branch April 4, 2022 07:02
@acenolaza acenolaza mentioned this pull request May 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants