From 5c524c7a98ae324afef4b8197634cf6c1418aa8e Mon Sep 17 00:00:00 2001 From: Gabriel Filipe Guimaraes de Freitas Date: Wed, 7 Feb 2024 00:38:35 -0300 Subject: [PATCH 1/2] [FEAT] Add user and password options --- .mqtt/mosquitto.conf | 2 +- Dockerfile | 4 ++++ README.md | 12 ++++++++++-- entrypoint.sh | 13 +++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 entrypoint.sh diff --git a/.mqtt/mosquitto.conf b/.mqtt/mosquitto.conf index 7056a9b..5d07edf 100644 --- a/.mqtt/mosquitto.conf +++ b/.mqtt/mosquitto.conf @@ -235,7 +235,7 @@ listener 1883 listener 9001 #socket_domain ipv4 protocol websockets -allow_anonymous true +#allow_anonymous true # By default, a listener will attempt to listen on all supported IP protocol # versions. If you do not have an IPv4 or IPv6 interface you may wish to diff --git a/Dockerfile b/Dockerfile index fdf4083..f8d171b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,8 @@ FROM eclipse-mosquitto +RUN apk add --no-cache mosquitto-clients +COPY entrypoint.sh /entrypoint.sh COPY .mqtt/mosquitto.conf /mosquitto/config/mosquitto.conf +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] EXPOSE 1883 EXPOSE 9001 diff --git a/README.md b/README.md index 4e0c3ed..cf8cc9d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## English ### Description -MQTT Server pre configured with default options to run 'plug and play' +MQTT Server pre configured with default options to run 'plug and play'. User and password can be set with `USER` and `PASSWORD` parameters. ### How to use @@ -13,11 +13,15 @@ Just run from a terminal: ```sh docker run -d -p 1883:1883 -p 9001:9001 --name mosquitto ggfto/mosquitto:latest ``` +With user and password: +```sh +docker run -d -p 1883:1883 -p 9001:9001 -e USER=myuser -e PASSWORD=mypassword --name mosquitto ggfto/mosquitto:latest +``` ## Português ### Descrição -Servidor MQTT pré-configurado com opções padrão para rodar sem a necessidade de ajustar algo +Servidor MQTT pré-configurado com opções padrão para rodar sem a necessidade de ajustar algo. Usuário e senha podem ser configurados com os parâmetros `USER` e `PASSWORD` ### Como usar @@ -25,3 +29,7 @@ Apenas execute a partir de um terminal: ```sh docker run -d -p 1883:1883 -p 9001:9001 --name mosquitto ggfto/mosquitto:latest ``` +Com usuário e senha: +```sh +docker run -d -p 1883:1883 -p 9001:9001 -e USER=myuser -e PASSWORD=mypassword --name mosquitto ggfto/mosquitto:latest +``` diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..c8b42de --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh +if [ ! -f /mosquitto/config/pwfile ]; then + if [ -n "$USER" ] && [ -n "$PASSWORD" ]; then + mosquitto_passwd -b -c /mosquitto/config/pwfile "$USER" "$PASSWORD" + chmod 700 /mosquitto/config/pwfile + chown mosquitto:mosquitto /mosquitto/config/pwfile + echo "password_file /mosquitto/config/pwfile" >> /mosquitto/config/mosquitto.conf + echo "allow_anonymous false" >> /mosquitto/config/mosquitto.conf + else + echo "allow_anonymous true" >> /mosquitto/config/mosquitto.conf + fi +fi +exec mosquitto -c /mosquitto/config/mosquitto.conf \ No newline at end of file From f9297b78abd5c9cc8f64cdb959b3fa383edc7423 Mon Sep 17 00:00:00 2001 From: Gabriel Filipe Guimaraes de Freitas Date: Wed, 7 Feb 2024 13:21:19 -0300 Subject: [PATCH 2/2] [OPS] ci update --- .github/workflows/ci.yml | 92 ++++++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0382b4..bfb1cf6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,8 +1,6 @@ name: ci on: - schedule: - - cron: "0 0 1 * *" push: branches: - "main" @@ -11,33 +9,63 @@ jobs: docker: runs-on: ubuntu-latest steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v4 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/mosquitto:latest - - - name: Update repo description - uses: peter-evans/dockerhub-description@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - repository: ${{ secrets.DOCKERHUB_USERNAME }}/mosquitto \ No newline at end of file + - + name: Checkout + uses: actions/checkout@v4 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Generate Release + id: release + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + uses: rymndhng/release-on-push-action@master + with: + bump_version_scheme: minor + use_github_release_notes: true + tag_prefix: v + - + name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ github.repository }}:latest, ${{ github.repository }}:${{steps.release.outputs.version}} + - + name: Update repo description + uses: peter-evans/dockerhub-description@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: ${{ github.repository }} + - + name: Success Discord Notification + if: success() + uses: rjstone/discord-webhook-notify@v1 + with: + severity: info + details: Sucesso no build! + username: Octocat + avatarUrl: https://github.githubassets.com/images/modules/logos_page/Octocat.png + webhookUrl: ${{secrets.DISCORD_WEBHOOK}} + - + name: Failure Discord Notification + if: failure() + uses: rjstone/discord-webhook-notify@v1 + with: + severity: error + details: ${{ join(steps.build.outputs.*, '\n') }} + username: Octocat + avatarUrl: https://github.githubassets.com/images/modules/logos_page/Octocat.png + webhookUrl: ${{secrets.DISCORD_WEBHOOK}} \ No newline at end of file