Skip to content

Commit

Permalink
Add docker entrypoint script for enabling swapfile
Browse files Browse the repository at this point in the history
  • Loading branch information
scottohara committed Jul 3, 2023
1 parent 2eeb302 commit 4211fd6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ RUN mkdir -p tmp/pids

COPY --link --chown=loot \
config.ru \
docker-entrypoint \
Gemfile* \
Rakefile ./

Expand All @@ -89,4 +90,6 @@ COPY --link --chown=loot --from=frontend build/public public/

EXPOSE 3000

USER root
ENTRYPOINT ["/loot/docker-entrypoint"]
CMD ["bundle", "exec", "puma"]
18 changes: 18 additions & 0 deletions docker-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh -e

# This entrypoint script is customised for use with Alpine Linux and Fly.io

# If the user is root
if [ $(id -u) -eq 0 ]; then
# Set the swappiness level to 10
sysctl --write vm.swappiness=10

# Enable the swapfile
swapon /swapfile

# Switch to a non-root system user and re-execute the command
exec su --shell /bin/sh loot --command "$0 $*"
fi

# Execute the script args as a command
$@
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@
"deploy": "fly deploy --build-arg NODE_VERSION=$npm_package_engines_node --build-arg NPM_VERSION=$npm_package_engines_npm --build-arg RUBY_VERSION=$npm_package_engines_ruby",
"deploy:staging": "npm run deploy -- --app loottest",
"deploy:production": "npm run deploy -- --app lootprod",
"swap:configure": "fly ssh console --command 'sysctl --write vm.swappiness=10'",
"swap:on": "fly ssh console --command 'swapon /swapfile'",
"postdeploy:staging": "npm run swap:configure -- --app loottest && npm run swap:on -- --app loottest",
"postdeploy:production": "npm run swap:configure -- --app lootprod && npm run swap:on -- --app lootprod",
"swap:check": "fly ssh console --command 'free'"
},
"engines": {
Expand Down

0 comments on commit 4211fd6

Please sign in to comment.