-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e4d81e
commit 204e49a
Showing
7 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Docker release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "v[0-9]+.[0-9]+" | ||
|
||
jobs: | ||
build: | ||
environment: release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check ref name | ||
run: | | ||
if [[ ! "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+$ ]]; then | ||
echo "Bad tag or branch name '${{ github.ref_name }}': it must be like 'v1.0'" | ||
exit 1 | ||
fi | ||
- 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_REGISTRY_USER }} | ||
password: ${{ secrets.DOCKER_REGISTRY_KEY }} | ||
- name: Define tags | ||
id: tags | ||
run: | | ||
ver=$(echo "${{ github.ref_name }}" | perl -pe 's/^v(\d+)\.(\d+)$/\1.\2/') | ||
base_ver=$(echo "${{ github.ref_name }}" | perl -pe 's/^v(\d+)\.(\d+)$/\1/') | ||
tags="${{ secrets.IMAGE_NAME }}:$ver" | ||
tags="$tags,${{ secrets.IMAGE_NAME }}:$base_ver" | ||
tags="$tags,${{ secrets.IMAGE_NAME }}:latest" | ||
echo "Defined tags: $tags" | ||
echo "::set-output name=value::$tags" | ||
- name: Build and push | ||
uses: docker/build-push-action@v3 | ||
with: | ||
push: true | ||
tags: "${{ steps.tags.outputs.value }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
#Ipython Notebook | ||
.ipynb_checkpoints | ||
|
||
# IDE | ||
.idea | ||
|
||
# db | ||
tests/db.sqlite3 | ||
|
||
# node | ||
node_modules/ | ||
package-lock.json | ||
package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
1.0 (2022-08-10) | ||
================== | ||
* First release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
FROM node:14-bullseye | ||
|
||
ARG MJML_VERSION=4.12.0 | ||
ARG EXPOSE=28101 | ||
|
||
ENV WORKDIR /app | ||
ENV SCRIPTSDIR /scripts | ||
ENV PATH "$SCRIPTSDIR:${PATH}" | ||
ENV HOST="0.0.0.0" | ||
ENV PORT=$EXPOSE | ||
|
||
COPY entrypoint.sh $SCRIPTSDIR/ | ||
RUN chmod +x $SCRIPTSDIR/*.sh | ||
|
||
|
||
RUN set -ex; \ | ||
npm init -y; \ | ||
npm install mjml@${MJML_VERSION} | ||
|
||
COPY tcpserver.js $WORKDIR/ | ||
|
||
WORKDIR $WORKDIR | ||
|
||
EXPOSE $EXPOSE | ||
|
||
ENTRYPOINT ["entrypoint.sh"] | ||
|
||
CMD ["--mjml.minify=true", "--mjml.validationLevel=strict"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
MJML TCP-Server | ||
=============== | ||
|
||
A `MJML <https://mjml.io/>`_ Server over TCP protocol. | ||
|
||
Mainly created for `django-mjml <https://github.com/liminspace/django-mjml>`_. | ||
|
||
| | ||
Using directly | ||
-------------- | ||
|
||
You can run the server just running the file with arguments like:: | ||
|
||
$ node tcpserver.js --host=0.0.0.0 --port=28101 --mjml.minify=true --mjml.validationLevel=strict | ||
|
||
|
||
Using Docker | ||
------------ | ||
|
||
Build the image:: | ||
|
||
$ docker build -t mjml-tcpserver . | ||
|
||
You can specify build arguments:: | ||
|
||
$ docker build -t mjml-tcpserver \ | ||
--build-arg MJML_VERSION=4.12.0 \ | ||
--build-arg EXPOSE=28101 \ | ||
--no-cache . | ||
|
||
Look at the Dockerfile to see the default values of arguments. | ||
|
||
Then run a docker container:: | ||
|
||
$ docker run -d --rm -p 28101:28101 mjml-tcpserver | ||
|
||
You can set host and port of the server using env vars:: | ||
|
||
$ docker run -d --rm -p 28105:28105 -e HOST=127.0.0.1 -e PORT=28105 mjml-tcpserver | ||
|
||
To set mjml options pass arguments as cmd using `mjml.` prefix:: | ||
|
||
$ docker run -d --rm -p 28101:28101 mjml-tcpserver --mjml.minify=true --mjml.validationLevel=strict | ||
|
||
All MJML arguments are listed `here <https://documentation.mjml.io/#inside-node-js>`_. | ||
|
||
|
||
Stop the server on touch a file | ||
------------------------------- | ||
|
||
If you wish the server to be stopped when a file is touched, use `--touchstop=/tmp/mjmltcpserver.stop`. | ||
|
||
Be sure the file exists. In case with Docker you can mount that file using a volume. | ||
|
||
|
||
Daemonize the server using supervisor | ||
------------------------------------- | ||
|
||
Example of configuration file:: | ||
|
||
/etc/supervisor/conf.d/mjmltcpserver.conf | ||
|
||
[program:mjmltcpserver] | ||
user=user | ||
environment=NODE_PATH=/home/user/node_modules | ||
command=node | ||
/home/user/mjml-tcpserver/tcpserver.js | ||
--port=28101 --host=127.0.0.1 --touchstop=/tmp/mjmltcpserver.stop --mjml.minify=true --mjml.validationLevel=strict | ||
stdout_logfile=/var/log/supervisor/mjmltcpserver.log | ||
autostart=true | ||
autorestart=true | ||
redirect_stderr=true | ||
stopwaitsecs=10 | ||
stopsignal=INT | ||
|
||
|
||
Docker compose | ||
-------------- | ||
|
||
Example:: | ||
|
||
services: | ||
mjml-1: | ||
image: liminspace/mjml-tcpserver:1 | ||
restart: always | ||
ports: | ||
- "28101:28101" | ||
|
||
mjml-2: | ||
image: liminspace/mjml-tcpserver:1 | ||
restart: always | ||
environment: | ||
HOST: "0.0.0.0" | ||
PORT: "28102" | ||
expose: | ||
- "28102" | ||
ports: | ||
- "28102:28102" | ||
command: ["--mjml.minify=true", "--mjml.validationLevel=strict"] | ||
|
||
mjml-3: | ||
build: | ||
context: . | ||
args: | ||
- MJML_VERSION=4.12.0 | ||
- EXPOSE=28103 | ||
restart: always | ||
ports: | ||
- "28103:28103" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e # Exit immediately if a command exits with a non-zero status. | ||
|
||
NODE="node" | ||
APP="tcpserver.js" | ||
BASE_APP_ARGS="--host=$HOST --port=$PORT" | ||
|
||
if [ "${1:0:1}" = '-' ]; then | ||
set -- "$APP" "$@" "$BASE_APP_ARGS" | ||
fi | ||
|
||
if [ "${1}" = "$APP" ]; then | ||
set -- "$NODE" "$@" | ||
fi | ||
|
||
exec ${@} |
Oops, something went wrong.