From ecf6fd4defdb1a5b496bce73ccafd783d61bf884 Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 21:05:15 -0400 Subject: [PATCH 01/12] - cleanup jhdbot dockerfile + directory --- JHDBot/.dockerignore | 1 - JHDBot/Dockerfile | 29 ++++-- JHDBot/Pipfile | 13 --- JHDBot/Pipfile.lock | 208 ------------------------------------------- docker-compose.yml | 34 +++---- 5 files changed, 38 insertions(+), 247 deletions(-) delete mode 100644 JHDBot/.dockerignore delete mode 100644 JHDBot/Pipfile delete mode 100644 JHDBot/Pipfile.lock diff --git a/JHDBot/.dockerignore b/JHDBot/.dockerignore deleted file mode 100644 index ebaaed1..0000000 --- a/JHDBot/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -gifs diff --git a/JHDBot/Dockerfile b/JHDBot/Dockerfile index 91ab9e8..2a128ae 100644 --- a/JHDBot/Dockerfile +++ b/JHDBot/Dockerfile @@ -1,9 +1,8 @@ -FROM python:3.7.8-alpine +FROM --platform=${TARGETPLATFORM:-linux/amd64} python:3.7.8-alpine -RUN mkdir -p /usr/src/app -RUN mkdir /usr/src/app/gifs -WORKDIR /usr/src/app +ARG TARGETPLATFORM +# Install packages RUN apk add --update --no-cache \ gcc \ python3-dev \ @@ -15,10 +14,24 @@ RUN apk add --update --no-cache \ libxslt-dev \ libxslt -COPY bot.py . -COPY cogs . -COPY requirements.txt . +# Add non root user +RUN addgroup -S app && adduser app -S -G app -RUN pip install -r requirements.txt +WORKDIR /home/app/ + +# Copy project files +COPY bot.py . +COPY requirements.txt . +COPY cogs . +COPY gifs . + + +RUN chown -R app /home/app && \ + mkdir -p /home/app/python && chown -R app /home/app +USER app +ENV PATH=$PATH:/home/app/.local/bin:/home/app/python/bin/ +ENV PYTHONPATH=$PYTHONPATH:/home/app/python + +RUN pip install -r requirements.txt --target=/home/app/python --no-cache-dir CMD ["python", "bot.py"] diff --git a/JHDBot/Pipfile b/JHDBot/Pipfile deleted file mode 100644 index 3107703..0000000 --- a/JHDBot/Pipfile +++ /dev/null @@ -1,13 +0,0 @@ -[[source]] -name = "pypi" -url = "https://pypi.org/simple" -verify_ssl = true - -[dev-packages] - -[packages] -discord = "*" -python-dotenv = "*" - -[requires] -python_version = "3.7" diff --git a/JHDBot/Pipfile.lock b/JHDBot/Pipfile.lock deleted file mode 100644 index f5f2d77..0000000 --- a/JHDBot/Pipfile.lock +++ /dev/null @@ -1,208 +0,0 @@ -{ - "_meta": { - "hash": { - "sha256": "3e1396f5d982ba5e7849df17c0bf9ecd4698d372a6862c99af99f404b81b4613" - }, - "pipfile-spec": 6, - "requires": { - "python_version": "3.7" - }, - "sources": [ - { - "name": "pypi", - "url": "https://pypi.org/simple", - "verify_ssl": true - } - ] - }, - "default": { - "aiohttp": { - "hashes": [ - "sha256:119feb2bd551e58d83d1b38bfa4cb921af8ddedec9fad7183132db334c3133e0", - "sha256:16d0683ef8a6d803207f02b899c928223eb219111bd52420ef3d7a8aa76227b6", - "sha256:2eb3efe243e0f4ecbb654b08444ae6ffab37ac0ef8f69d3a2ffb958905379daf", - "sha256:2ffea7904e70350da429568113ae422c88d2234ae776519549513c8f217f58a9", - "sha256:40bd1b101b71a18a528ffce812cc14ff77d4a2a1272dfb8b11b200967489ef3e", - "sha256:418597633b5cd9639e514b1d748f358832c08cd5d9ef0870026535bd5eaefdd0", - "sha256:481d4b96969fbfdcc3ff35eea5305d8565a8300410d3d269ccac69e7256b1329", - "sha256:4c1bdbfdd231a20eee3e56bd0ac1cd88c4ff41b64ab679ed65b75c9c74b6c5c2", - "sha256:5563ad7fde451b1986d42b9bb9140e2599ecf4f8e42241f6da0d3d624b776f40", - "sha256:58c62152c4c8731a3152e7e650b29ace18304d086cb5552d317a54ff2749d32a", - "sha256:5b50e0b9460100fe05d7472264d1975f21ac007b35dcd6fd50279b72925a27f4", - "sha256:5d84ecc73141d0a0d61ece0742bb7ff5751b0657dab8405f899d3ceb104cc7de", - "sha256:5dde6d24bacac480be03f4f864e9a67faac5032e28841b00533cd168ab39cad9", - "sha256:5e91e927003d1ed9283dee9abcb989334fc8e72cf89ebe94dc3e07e3ff0b11e9", - "sha256:62bc216eafac3204877241569209d9ba6226185aa6d561c19159f2e1cbb6abfb", - "sha256:6c8200abc9dc5f27203986100579fc19ccad7a832c07d2bc151ce4ff17190076", - "sha256:6ca56bdfaf825f4439e9e3673775e1032d8b6ea63b8953d3812c71bd6a8b81de", - "sha256:71680321a8a7176a58dfbc230789790639db78dad61a6e120b39f314f43f1907", - "sha256:7c7820099e8b3171e54e7eedc33e9450afe7cd08172632d32128bd527f8cb77d", - "sha256:7dbd087ff2f4046b9b37ba28ed73f15fd0bc9f4fdc8ef6781913da7f808d9536", - "sha256:822bd4fd21abaa7b28d65fc9871ecabaddc42767884a626317ef5b75c20e8a2d", - "sha256:8ec1a38074f68d66ccb467ed9a673a726bb397142c273f90d4ba954666e87d54", - "sha256:950b7ef08b2afdab2488ee2edaff92a03ca500a48f1e1aaa5900e73d6cf992bc", - "sha256:99c5a5bf7135607959441b7d720d96c8e5c46a1f96e9d6d4c9498be8d5f24212", - "sha256:b84ad94868e1e6a5e30d30ec419956042815dfaea1b1df1cef623e4564c374d9", - "sha256:bc3d14bf71a3fb94e5acf5bbf67331ab335467129af6416a437bd6024e4f743d", - "sha256:c2a80fd9a8d7e41b4e38ea9fe149deed0d6aaede255c497e66b8213274d6d61b", - "sha256:c44d3c82a933c6cbc21039326767e778eface44fca55c65719921c4b9661a3f7", - "sha256:cc31e906be1cc121ee201adbdf844522ea3349600dd0a40366611ca18cd40e81", - "sha256:d5d102e945ecca93bcd9801a7bb2fa703e37ad188a2f81b1e65e4abe4b51b00c", - "sha256:dd7936f2a6daa861143e376b3a1fb56e9b802f4980923594edd9ca5670974895", - "sha256:dee68ec462ff10c1d836c0ea2642116aba6151c6880b688e56b4c0246770f297", - "sha256:e76e78863a4eaec3aee5722d85d04dcbd9844bc6cd3bfa6aa880ff46ad16bfcb", - "sha256:eab51036cac2da8a50d7ff0ea30be47750547c9aa1aa2cf1a1b710a1827e7dbe", - "sha256:f4496d8d04da2e98cc9133e238ccebf6a13ef39a93da2e87146c8c8ac9768242", - "sha256:fbd3b5e18d34683decc00d9a360179ac1e7a320a5fee10ab8053ffd6deab76e0", - "sha256:feb24ff1226beeb056e247cf2e24bba5232519efb5645121c4aea5b6ad74c1f2" - ], - "index": "pypi", - "version": "==3.7.4" - }, - "async-timeout": { - "hashes": [ - "sha256:0c3c816a028d47f659d6ff5c745cb2acf1f966da1fe5c19c77a70282b25f4c5f", - "sha256:4291ca197d287d274d0b6cb5d6f8f8f82d434ed288f962539ff18cc9012f9ea3" - ], - "version": "==3.0.1" - }, - "attrs": { - "hashes": [ - "sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6", - "sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700" - ], - "version": "==20.3.0" - }, - "chardet": { - "hashes": [ - "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", - "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" - ], - "version": "==3.0.4" - }, - "discord": { - "hashes": [ - "sha256:9d4debb4a37845543bd4b92cb195bc53a302797333e768e70344222857ff1559", - "sha256:ff6653655e342e7721dfb3f10421345fd852c2a33f2cca912b1c39b3778a9429" - ], - "index": "pypi", - "version": "==1.0.1" - }, - "discord.py": { - "hashes": [ - "sha256:3df148daf6fbcc7ab5b11042368a3cd5f7b730b62f09fb5d3cbceff59bcfbb12", - "sha256:ba8be99ff1b8c616f7b6dcb700460d0222b29d4c11048e74366954c465fdd05f" - ], - "version": "==1.6.0" - }, - "idna": { - "hashes": [ - "sha256:5205d03e7bcbb919cc9c19885f9920d622ca52448306f2377daede5cf3faac16", - "sha256:c5b02147e01ea9920e6b0a3f1f7bb833612d507592c837a6c49552768f4054e1" - ], - "version": "==3.1" - }, - "multidict": { - "hashes": [ - "sha256:018132dbd8688c7a69ad89c4a3f39ea2f9f33302ebe567a879da8f4ca73f0d0a", - "sha256:051012ccee979b2b06be928a6150d237aec75dd6bf2d1eeeb190baf2b05abc93", - "sha256:05c20b68e512166fddba59a918773ba002fdd77800cad9f55b59790030bab632", - "sha256:07b42215124aedecc6083f1ce6b7e5ec5b50047afa701f3442054373a6deb656", - "sha256:0e3c84e6c67eba89c2dbcee08504ba8644ab4284863452450520dad8f1e89b79", - "sha256:0e929169f9c090dae0646a011c8b058e5e5fb391466016b39d21745b48817fd7", - "sha256:1ab820665e67373de5802acae069a6a05567ae234ddb129f31d290fc3d1aa56d", - "sha256:25b4e5f22d3a37ddf3effc0710ba692cfc792c2b9edfb9c05aefe823256e84d5", - "sha256:2e68965192c4ea61fff1b81c14ff712fc7dc15d2bd120602e4a3494ea6584224", - "sha256:2f1a132f1c88724674271d636e6b7351477c27722f2ed789f719f9e3545a3d26", - "sha256:37e5438e1c78931df5d3c0c78ae049092877e5e9c02dd1ff5abb9cf27a5914ea", - "sha256:3a041b76d13706b7fff23b9fc83117c7b8fe8d5fe9e6be45eee72b9baa75f348", - "sha256:3a4f32116f8f72ecf2a29dabfb27b23ab7cdc0ba807e8459e59a93a9be9506f6", - "sha256:46c73e09ad374a6d876c599f2328161bcd95e280f84d2060cf57991dec5cfe76", - "sha256:46dd362c2f045095c920162e9307de5ffd0a1bfbba0a6e990b344366f55a30c1", - "sha256:4b186eb7d6ae7c06eb4392411189469e6a820da81447f46c0072a41c748ab73f", - "sha256:54fd1e83a184e19c598d5e70ba508196fd0bbdd676ce159feb412a4a6664f952", - "sha256:585fd452dd7782130d112f7ddf3473ffdd521414674c33876187e101b588738a", - "sha256:5cf3443199b83ed9e955f511b5b241fd3ae004e3cb81c58ec10f4fe47c7dce37", - "sha256:6a4d5ce640e37b0efcc8441caeea8f43a06addace2335bd11151bc02d2ee31f9", - "sha256:7df80d07818b385f3129180369079bd6934cf70469f99daaebfac89dca288359", - "sha256:806068d4f86cb06af37cd65821554f98240a19ce646d3cd24e1c33587f313eb8", - "sha256:830f57206cc96ed0ccf68304141fec9481a096c4d2e2831f311bde1c404401da", - "sha256:929006d3c2d923788ba153ad0de8ed2e5ed39fdbe8e7be21e2f22ed06c6783d3", - "sha256:9436dc58c123f07b230383083855593550c4d301d2532045a17ccf6eca505f6d", - "sha256:9dd6e9b1a913d096ac95d0399bd737e00f2af1e1594a787e00f7975778c8b2bf", - "sha256:ace010325c787c378afd7f7c1ac66b26313b3344628652eacd149bdd23c68841", - "sha256:b47a43177a5e65b771b80db71e7be76c0ba23cc8aa73eeeb089ed5219cdbe27d", - "sha256:b797515be8743b771aa868f83563f789bbd4b236659ba52243b735d80b29ed93", - "sha256:b7993704f1a4b204e71debe6095150d43b2ee6150fa4f44d6d966ec356a8d61f", - "sha256:d5c65bdf4484872c4af3150aeebe101ba560dcfb34488d9a8ff8dbcd21079647", - "sha256:d81eddcb12d608cc08081fa88d046c78afb1bf8107e6feab5d43503fea74a635", - "sha256:dc862056f76443a0db4509116c5cd480fe1b6a2d45512a653f9a855cc0517456", - "sha256:ecc771ab628ea281517e24fd2c52e8f31c41e66652d07599ad8818abaad38cda", - "sha256:f200755768dc19c6f4e2b672421e0ebb3dd54c38d5a4f262b872d8cfcc9e93b5", - "sha256:f21756997ad8ef815d8ef3d34edd98804ab5ea337feedcd62fb52d22bf531281", - "sha256:fc13a9524bc18b6fb6e0dbec3533ba0496bbed167c56d0aabefd965584557d80" - ], - "version": "==5.1.0" - }, - "python-dotenv": { - "hashes": [ - "sha256:25c0ff1a3e12f4bde8d592cc254ab075cfe734fc5dd989036716fd17ee7e5ec7", - "sha256:3b9909bc96b0edc6b01586e1eed05e71174ef4e04c71da5786370cebea53ad74" - ], - "index": "pypi", - "version": "==0.13.0" - }, - "typing-extensions": { - "hashes": [ - "sha256:7cb407020f00f7bfc3cb3e7881628838e69d8f3fcab2f64742a5e76b2f841918", - "sha256:99d4073b617d30288f569d3f13d2bd7548c3a7e4c8de87db09a9d29bb3a4a60c", - "sha256:dafc7639cde7f1b6e1acc0f457842a83e722ccca8eef5270af2d74792619a89f" - ], - "markers": "python_version < '3.8'", - "version": "==3.7.4.3" - }, - "yarl": { - "hashes": [ - "sha256:00d7ad91b6583602eb9c1d085a2cf281ada267e9a197e8b7cae487dadbfa293e", - "sha256:0355a701b3998dcd832d0dc47cc5dedf3874f966ac7f870e0f3a6788d802d434", - "sha256:15263c3b0b47968c1d90daa89f21fcc889bb4b1aac5555580d74565de6836366", - "sha256:2ce4c621d21326a4a5500c25031e102af589edb50c09b321049e388b3934eec3", - "sha256:31ede6e8c4329fb81c86706ba8f6bf661a924b53ba191b27aa5fcee5714d18ec", - "sha256:324ba3d3c6fee56e2e0b0d09bf5c73824b9f08234339d2b788af65e60040c959", - "sha256:329412812ecfc94a57cd37c9d547579510a9e83c516bc069470db5f75684629e", - "sha256:4736eaee5626db8d9cda9eb5282028cc834e2aeb194e0d8b50217d707e98bb5c", - "sha256:4953fb0b4fdb7e08b2f3b3be80a00d28c5c8a2056bb066169de00e6501b986b6", - "sha256:4c5bcfc3ed226bf6419f7a33982fb4b8ec2e45785a0561eb99274ebbf09fdd6a", - "sha256:547f7665ad50fa8563150ed079f8e805e63dd85def6674c97efd78eed6c224a6", - "sha256:5b883e458058f8d6099e4420f0cc2567989032b5f34b271c0827de9f1079a424", - "sha256:63f90b20ca654b3ecc7a8d62c03ffa46999595f0167d6450fa8383bab252987e", - "sha256:68dc568889b1c13f1e4745c96b931cc94fdd0defe92a72c2b8ce01091b22e35f", - "sha256:69ee97c71fee1f63d04c945f56d5d726483c4762845400a6795a3b75d56b6c50", - "sha256:6d6283d8e0631b617edf0fd726353cb76630b83a089a40933043894e7f6721e2", - "sha256:72a660bdd24497e3e84f5519e57a9ee9220b6f3ac4d45056961bf22838ce20cc", - "sha256:73494d5b71099ae8cb8754f1df131c11d433b387efab7b51849e7e1e851f07a4", - "sha256:7356644cbed76119d0b6bd32ffba704d30d747e0c217109d7979a7bc36c4d970", - "sha256:8a9066529240171b68893d60dca86a763eae2139dd42f42106b03cf4b426bf10", - "sha256:8aa3decd5e0e852dc68335abf5478a518b41bf2ab2f330fe44916399efedfae0", - "sha256:97b5bdc450d63c3ba30a127d018b866ea94e65655efaf889ebeabc20f7d12406", - "sha256:9ede61b0854e267fd565e7527e2f2eb3ef8858b301319be0604177690e1a3896", - "sha256:b2e9a456c121e26d13c29251f8267541bd75e6a1ccf9e859179701c36a078643", - "sha256:b5dfc9a40c198334f4f3f55880ecf910adebdcb2a0b9a9c23c9345faa9185721", - "sha256:bafb450deef6861815ed579c7a6113a879a6ef58aed4c3a4be54400ae8871478", - "sha256:c49ff66d479d38ab863c50f7bb27dee97c6627c5fe60697de15529da9c3de724", - "sha256:ce3beb46a72d9f2190f9e1027886bfc513702d748047b548b05dab7dfb584d2e", - "sha256:d26608cf178efb8faa5ff0f2d2e77c208f471c5a3709e577a7b3fd0445703ac8", - "sha256:d597767fcd2c3dc49d6eea360c458b65643d1e4dbed91361cf5e36e53c1f8c96", - "sha256:d5c32c82990e4ac4d8150fd7652b972216b204de4e83a122546dce571c1bdf25", - "sha256:d8d07d102f17b68966e2de0e07bfd6e139c7c02ef06d3a0f8d2f0f055e13bb76", - "sha256:e46fba844f4895b36f4c398c5af062a9808d1f26b2999c58909517384d5deda2", - "sha256:e6b5460dc5ad42ad2b36cca524491dfcaffbfd9c8df50508bddc354e787b8dc2", - "sha256:f040bcc6725c821a4c0665f3aa96a4d0805a7aaf2caf266d256b8ed71b9f041c", - "sha256:f0b059678fd549c66b89bed03efcabb009075bd131c248ecdf087bdb6faba24a", - "sha256:fcbb48a93e8699eae920f8d92f7160c03567b421bc17362a9ffbbd706a816f71" - ], - "version": "==1.6.3" - } - }, - "develop": {} -} diff --git a/docker-compose.yml b/docker-compose.yml index 8f676b4..181bee4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,23 +1,30 @@ version: '3' +networks: + frontend: + backend: + services: nginx: build: . container_name: nginx restart: "always" privileged: true - links: - - "webapp1:verify-app1" - - "webapp2:verify-app2" + networks: + - frontend ports: - "8080:80" jhd-bot: - build: JHDBot/. + build: + context: JHDBot/ + dockerfile: Dockerfile container_name: jhd-bot restart: "always" - volumes: - - ./JHDBot/gifs:/usr/src/app/gifs:rw + networks: + - backend + ports: + - "5000" environment: - DISCORD_API_TOKEN=${DISCORD_API_TOKEN} - BOT_PREFIX_CHARACTER=${BOT_PREFIX_CHARACTER} @@ -28,6 +35,10 @@ services: build: verify-web/. container_name: verify-app1 restart: "always" + networks: + - frontend + ports: + - "8080:8080" environment: - RECAPTCHA_PUBLIC_KEY=${RECAPTCHA_PUBLIC_KEY} - RECAPTCHA_PRIVATE_KEY=${RECAPTCHA_PRIVATE_KEY} @@ -36,14 +47,3 @@ services: - LOGGING_WEBHOOK_CHANNEL=${LOGGING_WEBHOOK_CHANNEL} - LOGGING_WEBHOOK_TOKEN=${LOGGING_WEBHOOK_TOKEN} - webapp2: - build: verify-web/. - container_name: verify-app2 - restart: "always" - environment: - - RECAPTCHA_PUBLIC_KEY=${RECAPTCHA_PUBLIC_KEY} - - RECAPTCHA_PRIVATE_KEY=${RECAPTCHA_PRIVATE_KEY} - - DISCORD_API_TOKEN=${DISCORD_API_TOKEN} - - DISCORD_SERVER_CHANNEL_ID=${DISCORD_SERVER_CHANNEL_ID} - - LOGGING_WEBHOOK_CHANNEL=${LOGGING_WEBHOOK_CHANNEL} - - LOGGING_WEBHOOK_TOKEN=${LOGGING_WEBHOOK_TOKEN} From e52440cba75a094b7d49337601b04812537ca370 Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 21:29:02 -0400 Subject: [PATCH 02/12] - add discordhealthcheck package for container restart - use updated pip freeze output from container --- JHDBot/Dockerfile | 2 ++ JHDBot/bot.py | 2 ++ JHDBot/requirements.txt | 30 ++++++++++++++++++++++++++++-- docker-compose.yml | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/JHDBot/Dockerfile b/JHDBot/Dockerfile index 2a128ae..f3e8439 100644 --- a/JHDBot/Dockerfile +++ b/JHDBot/Dockerfile @@ -34,4 +34,6 @@ ENV PYTHONPATH=$PYTHONPATH:/home/app/python RUN pip install -r requirements.txt --target=/home/app/python --no-cache-dir +HEALTHCHECK CMD discordhealthcheck || exit 1 + CMD ["python", "bot.py"] diff --git a/JHDBot/bot.py b/JHDBot/bot.py index b3ca275..5eea578 100644 --- a/JHDBot/bot.py +++ b/JHDBot/bot.py @@ -10,6 +10,7 @@ from discord import Intents from discord.ext import commands from dotenv import load_dotenv +import discordhealthcheck load_dotenv() @@ -21,6 +22,7 @@ ) # bot command prefix bot.remove_command("help") # Loading Cogs +discordhealthcheck.start(bot) extensions = ["moderation", "veteran", "general", "verification"] diff --git a/JHDBot/requirements.txt b/JHDBot/requirements.txt index 995258a..50b35d3 100644 --- a/JHDBot/requirements.txt +++ b/JHDBot/requirements.txt @@ -1,5 +1,31 @@ +aiohttp==3.7.4.post0 +appdirs==1.4.4 +async-timeout==3.0.1 +attrs==22.1.0 +beautifulsoup4==4.11.1 +bs4==0.0.1 +certifi==2022.6.15 +chardet==3.0.4 +cssselect==1.1.0 discord.py==1.7.3 -python-dotenv -urllib3==1.25.8 +discordhealthcheck==0.0.8 +fake-useragent==0.1.11 +idna==2.10 +importlib-metadata==4.12.0 +lxml==4.9.1 +multidict==6.0.2 +parse==1.19.0 +pyee==8.2.2 +pyppeteer==1.0.2 +pyquery==1.4.3 +python-dotenv==0.21.0 requests==2.23.0 requests-html==0.10.0 +soupsieve==2.3.2.post1 +tqdm==4.64.1 +typing-extensions==4.3.0 +urllib3==1.25.8 +w3lib==2.0.1 +websockets==10.3 +yarl==1.8.1 +zipp==3.8.1 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 181bee4..3229995 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ services: networks: - backend ports: - - "5000" + - "40404" environment: - DISCORD_API_TOKEN=${DISCORD_API_TOKEN} - BOT_PREFIX_CHARACTER=${BOT_PREFIX_CHARACTER} From d734f693aaf6857173455b78fde709d237e5cd5e Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 21:52:49 -0400 Subject: [PATCH 03/12] - Setup docker multi-stage build (builds .whl files in first image then copies those to fresh image to remove extra dependencies) --- JHDBot/Dockerfile | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/JHDBot/Dockerfile b/JHDBot/Dockerfile index f3e8439..940f44b 100644 --- a/JHDBot/Dockerfile +++ b/JHDBot/Dockerfile @@ -1,7 +1,13 @@ -FROM --platform=${TARGETPLATFORM:-linux/amd64} python:3.7.8-alpine +# Builder image +FROM --platform=${TARGETPLATFORM:-linux/amd64} python:3.7.8-alpine as builder ARG TARGETPLATFORM +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +WORKDIR /app + # Install packages RUN apk add --update --no-cache \ gcc \ @@ -14,25 +20,36 @@ RUN apk add --update --no-cache \ libxslt-dev \ libxslt +COPY requirements.txt . + +# Build python +RUN pip wheel --no-cache-dir --no-deps --wheel-dir /wheels -r requirements.txt + +# Final image; no build dependencies so image is smaller +FROM --platform=${TARGETPLATFORM:-linux/amd64} python:3.7.8-alpine + # Add non root user RUN addgroup -S app && adduser app -S -G app WORKDIR /home/app/ # Copy project files +COPY --from=builder /wheels ./wheels +COPY --from=builder /app/requirements.txt . + COPY bot.py . -COPY requirements.txt . COPY cogs . COPY gifs . - +# Setup permissions and user path RUN chown -R app /home/app && \ mkdir -p /home/app/python && chown -R app /home/app USER app ENV PATH=$PATH:/home/app/.local/bin:/home/app/python/bin/ ENV PYTHONPATH=$PYTHONPATH:/home/app/python -RUN pip install -r requirements.txt --target=/home/app/python --no-cache-dir +# Install previously built python wheels +RUN pip install --no-cache /home/app/wheels/* --target=/home/app/python HEALTHCHECK CMD discordhealthcheck || exit 1 From 417dafdd9ce516e141d53d743b6c93cb17cbc0a6 Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 22:26:29 -0400 Subject: [PATCH 04/12] - Update github actions using newer methods (builds linux/amd64 & linux/arm64) --- .github/workflows/workflow.yml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index a250129..db44944 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -61,20 +61,28 @@ jobs: needs: jhdbot-check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: docker/setup-buildx-action@v1 - - name: Login to DockerHub - uses: docker/login-action@v1 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to DockerHub + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v2 + - + name: Build and push + uses: docker/build-push-action@v3 with: - context: JHDBot file: ./JHDBot/Dockerfile + context: JHDBot + platforms: linux/amd64,linux/arm64 push: true - tags: jhdiscord/jhd-bot-docker:latest + tags: jhdiscord/jhd-bot-docker:${{ github.sha }} + verify-app-docker: name: Build and push Verify App From 445bff0d3876e430f198fbf655f02e165f0854fe Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 22:31:58 -0400 Subject: [PATCH 05/12] - Add image reference to latest --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index 3229995..ed58442 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,6 +16,7 @@ services: - "8080:80" jhd-bot: + image: jhdiscord/jhd-bot-docker:latest build: context: JHDBot/ dockerfile: Dockerfile From 795da426ea86ad31a2d9a6c6021a7c6df658441a Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 23:04:17 -0400 Subject: [PATCH 06/12] - Add building/testing on PR request to master branch --- .github/workflows/workflow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index db44944..f794b2c 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,6 +1,8 @@ name: Check Apps For Errors And Build Docker Images on: + pull_request: + branches: [ master ] push: branches: [ master ] From 41d0197cf1d7b4717cbe9b30c32e868e1380149c Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 23:09:54 -0400 Subject: [PATCH 07/12] - Fix github action context - Change nginx + verify_app to only push to SHA tag --- .github/workflows/workflow.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f794b2c..e1a6077 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -80,7 +80,7 @@ jobs: uses: docker/build-push-action@v3 with: file: ./JHDBot/Dockerfile - context: JHDBot + context: ./JHDBot platforms: linux/amd64,linux/arm64 push: true tags: jhdiscord/jhd-bot-docker:${{ github.sha }} @@ -104,7 +104,7 @@ jobs: context: verify-web file: ./verify-web/Dockerfile push: true - tags: jhdiscord/verify-app-docker:latest + tags: jhdiscord/verify-app-docker:${{ github.sha }} nginx-docker: name: Build and push nginx @@ -123,4 +123,4 @@ jobs: with: context: . push: true - tags: jhdiscord/nginx-docker:latest + tags: jhdiscord/nginx-docker:${{ github.sha }} From 299cf3e82d5c1bbefe92b33cc871001876bfc5a7 Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 23:16:21 -0400 Subject: [PATCH 08/12] - Fix github action context --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index e1a6077..ca5b5dc 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -80,7 +80,7 @@ jobs: uses: docker/build-push-action@v3 with: file: ./JHDBot/Dockerfile - context: ./JHDBot + context: ./JHDBot/. platforms: linux/amd64,linux/arm64 push: true tags: jhdiscord/jhd-bot-docker:${{ github.sha }} From 23f3b66fba98858fb98feaf8e4870c6f2e0b5f85 Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 23:26:54 -0400 Subject: [PATCH 09/12] - Fix github action context --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index ca5b5dc..79e0bce 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -79,8 +79,8 @@ jobs: name: Build and push uses: docker/build-push-action@v3 with: + context: . file: ./JHDBot/Dockerfile - context: ./JHDBot/. platforms: linux/amd64,linux/arm64 push: true tags: jhdiscord/jhd-bot-docker:${{ github.sha }} From 70e5481e9ac15362e98bab191e3c0da7b34d8c36 Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 23:40:04 -0400 Subject: [PATCH 10/12] - try to downgrade github action --- .github/workflows/workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 79e0bce..9170c96 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -77,9 +77,9 @@ jobs: password: ${{ secrets.DOCKER_TOKEN }} - name: Build and push - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v2 with: - context: . + context: JHDBot file: ./JHDBot/Dockerfile platforms: linux/amd64,linux/arm64 push: true From 33a5e2b0eaf00cbfab14167101f4341e77e59496 Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 23:52:10 -0400 Subject: [PATCH 11/12] - set original context/file --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 9170c96..744c07a 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -79,7 +79,7 @@ jobs: name: Build and push uses: docker/build-push-action@v2 with: - context: JHDBot + context: ./JHDBot file: ./JHDBot/Dockerfile platforms: linux/amd64,linux/arm64 push: true From 3a407d89c091a662a06c6982add9e2bfaa9347c9 Mon Sep 17 00:00:00 2001 From: naphal Date: Thu, 8 Sep 2022 23:55:41 -0400 Subject: [PATCH 12/12] - add checkout action back in --- .github/workflows/workflow.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 744c07a..f9dbe4c 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -63,6 +63,9 @@ jobs: needs: jhdbot-check runs-on: ubuntu-latest steps: + - + name: Checkout repo + uses: actions/checkout@v2 - name: Set up QEMU uses: docker/setup-qemu-action@v2