diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index a57ad91..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Build and push - -on: - push: - branches: master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: checkout code - uses: actions/checkout@v2 - - name: install buildx - id: buildx - uses: crazy-max/ghaction-docker-buildx@v1 - with: - buildx-version: latest - - name: login to docker hub - run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin - - run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV - shell: bash - - name: build the image - run: | - case $GITHUB_REF in - refs/tags/*) VERSION=${GITHUB_REF#refs/tags/};; - refs/heads/*) VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g');; - refs/pull/*) VERSION=pr-${{ github.event.number }};; - *) VERSION=sha-${GITHUB_SHA::8};; - esac - echo $VERSION - [ "$VERSION" == "master" ] && VERSION=latest - docker buildx build --push \ - --tag "${{ secrets.DOCKER_USERNAME }}"/${REPOSITORY_NAME}:${VERSION} \ - --platform linux/amd64,linux/arm/v7,linux/arm/v6,linux/arm64 . diff --git a/.github/workflows/docker_build.yml b/.github/workflows/docker_build.yml new file mode 100644 index 0000000..f85bffd --- /dev/null +++ b/.github/workflows/docker_build.yml @@ -0,0 +1,52 @@ +name: Build and push + +on: + pull_request: + branches: [ master ] + push: + branches: [ master ] + +jobs: + test_build: + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Build + id: docker_build + uses: docker/build-push-action@v2 + with: + platforms: linux/amd64,linux/arm64, linux/arm/v7 + + build_and_push: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/master' + needs: test_build + steps: + - name: checkout code + uses: actions/checkout@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + platforms: linux/amd64,linux/arm64, linux/arm/v7 + labels: | + org.opencontainers.image.source=https://github.com/${{ github.repository }} + org.opencontainers.image.revision=${{ github.sha }} + tags: | + ${{ secrets.DOCKER_USERNAME }}/bt-mqtt-gateway:${{ github.sha }} + ${{ secrets.DOCKER_USERNAME }}/bt-mqtt-gateway:latest diff --git a/Dockerfile b/Dockerfile index 224c4b3..3c7c084 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,21 @@ -FROM python:3.8-alpine3.12 +FROM python:3.8-alpine ENV DEBUG false -RUN mkdir application -WORKDIR /application - -COPY requirements.txt /application - -RUN apk add --no-cache tzdata bluez bluez-libs sudo bluez-deprecated && \ - ln -s /config.yaml ./config.yaml && \ - pip install -r requirements.txt - +RUN mkdir /application COPY . /application -RUN apk add --no-cache --virtual build-dependencies git bluez-dev musl-dev make gcc glib-dev musl-dev && \ - pip install `./gateway.py -r all` && \ +WORKDIR /application + +RUN apk add --no-cache tzdata bluez bluez-libs sudo bluez-deprecated && \ + apk add --no-cache --virtual build-dependencies git bluez-dev musl-dev make gcc glib-dev musl-dev && \ + pip install --no-cache-dir -r requirements.txt && \ + pip install --no-cache-dir `./gateway.py -r all` && \ apk del build-dependencies COPY ./start.sh /start.sh RUN chmod +x /start.sh +VOLUME /application/config.yaml + ENTRYPOINT ["/bin/sh", "-c", "/start.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 3039408..275f084 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: #environment: # - DEBUG=true volumes: - - ./config.yaml:/config.yaml + - ./config.yaml:/application/config.yaml cap_add: - NET_ADMIN - NET_RAW diff --git a/start.sh b/start.sh index 0c39ada..d6b155c 100644 --- a/start.sh +++ b/start.sh @@ -1,12 +1,10 @@ #!/bin/sh -if ! [ -f '/config.yaml' ]; then - echo "There is no config.yaml! An example is created." - cp /application/config.yaml.example /config.yaml.example +if ! [ -f '/application/config.yaml' ]; then + echo "There is no config.yaml! Check example config: https://github.com/zewelor/bt-mqtt-gateway/blob/master/config.yaml.example" exit 1 fi -cd /application if [ "$DEBUG" = 'true' ]; then echo "Start in debug mode" python3 ./gateway.py -d