diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f015dfa --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +Dockerfile +.dockerignore +**/.git* +**/example_plugins +**/gui +**/*.md +**/*.yaml +**/*.iss diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..db96384 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,49 @@ +name: Create and publish a Docker image + +on: + release: + types: [published] + branches: ['latest'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Get Release Tag + id: get_release_tag + run: echo "version=$(echo $GITHUB_REF | cut -d'/' -f3)" >> $GITHUB_OUTPUT + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push Docker image + id: push + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + platforms: linux/arm64,linux/amd64 + push: true + outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=A relay between a Matrix.org room and a Meshtastic radio,org.opencontainers.image.title=MMRelay-Docker + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8f74c92 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# syntax=docker/dockerfile:1 + +ARG python=python:3.9-slim + +# build stage +FROM ${python} AS build + +RUN apt-get update \ + && apt-get install gcc -y + +RUN useradd mmrelay + +USER mmrelay + +ADD --chown=mmrelay:mmrelay https://github.com/geoffwhittington/meshtastic-matrix-relay.git /opt/mmrelay + +WORKDIR /opt/mmrelay +ENV PATH="/opt/mmrelay/bin:$PATH" + +RUN python -m venv /opt/mmrelay \ + && python -m pip install --upgrade pip \ + && pip install -r requirements.txt + +# deploy stage +FROM ${python} AS final + +RUN apt-get update \ + && apt-get install git -y + +RUN useradd mmrelay + +USER mmrelay + +WORKDIR /opt/mmrelay + +ENV PATH="/opt/mmrelay/bin:$PATH" + +COPY --chown=mmrelay:mmrelay --from=build /opt/mmrelay /opt/mmrelay + +CMD ["python", "main.py"]