From f3cb24540d678fbeb69a89ae8f067b541e48302c Mon Sep 17 00:00:00 2001 From: Maxim Zalysin Date: Thu, 7 Jan 2021 21:12:40 +0300 Subject: [PATCH 1/3] Add multi-platform build and ubuntu based image --- .github/workflows/build-push.yml | 23 +++++++---- alpine/Dockerfile => Dockerfile.alpine | 0 debian/Dockerfile => Dockerfile.debian | 0 Dockerfile.ubuntu | 18 +++++++++ README.md | 53 ++++++++++---------------- 5 files changed, 55 insertions(+), 39 deletions(-) rename alpine/Dockerfile => Dockerfile.alpine (100%) rename debian/Dockerfile => Dockerfile.debian (100%) create mode 100644 Dockerfile.ubuntu diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index af9e9a7..56728b4 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -16,10 +16,18 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - base: [alpine, debian] + platform: + - os: alpine + arch: linux/amd64,linux/386,linux/arm/v6 + - os: debian + arch: linux/amd64 + - os: ubuntu + arch: linux/amd64,linux/arm/v7,linux/arm64/v8 steps: - name: Checkout 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 Docker Hub @@ -28,7 +36,7 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Set environment DOCKERHUB_IMAGE_TAGS on master - if: github.ref == 'refs/heads/master' && matrix.base == 'alpine' + if: github.ref == 'refs/heads/master' && matrix.platform.os == 'alpine' run: echo "DOCKERHUB_IMAGE_TAGS=$DOCKERHUB_REPOSITORY:latest" >> $GITHUB_ENV - name: Set environment DOCKERHUB_IMAGE_TAGS if: github.ref != 'refs/heads/master' @@ -37,10 +45,10 @@ jobs: _BRANCH=${GITHUB_REF##*/} _VERSION=${_BRANCH#v*} _MAJOR_VERSION=${_VERSION%.*} - _DOCKERHUB_IMAGE_TAGS="$DOCKERHUB_REPOSITORY:$_VERSION-${{ matrix.base }}" - _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:$_MAJOR_VERSION-${{ matrix.base }}" - _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:${{ matrix.base }}" - if [ "${{ matrix.base }}" == "alpine" ]; then + _DOCKERHUB_IMAGE_TAGS="$DOCKERHUB_REPOSITORY:$_VERSION-${{ matrix.platform.os }}" + _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:$_MAJOR_VERSION-${{ matrix.platform.os }}" + _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:${{ matrix.platform.os }}" + if [ "${{ matrix.platform.os }}" == "alpine" ]; then _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:$_VERSION" _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:$_MAJOR_VERSION" fi @@ -49,6 +57,7 @@ jobs: if: env.DOCKERHUB_IMAGE_TAGS != '' uses: docker/build-push-action@v2 with: - file: ${{ matrix.base }}/Dockerfile + file: Dockerfile.${{ matrix.platform.os }} tags: ${{ env.DOCKERHUB_IMAGE_TAGS }} + platforms: matrix.platform.arch push: true diff --git a/alpine/Dockerfile b/Dockerfile.alpine similarity index 100% rename from alpine/Dockerfile rename to Dockerfile.alpine diff --git a/debian/Dockerfile b/Dockerfile.debian similarity index 100% rename from debian/Dockerfile rename to Dockerfile.debian diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu new file mode 100644 index 0000000..9e85f7b --- /dev/null +++ b/Dockerfile.ubuntu @@ -0,0 +1,18 @@ +FROM adoptopenjdk:8-jre-hotspot-focal + +ENV TRACCAR_VERSION 4.11 + +WORKDIR /opt/traccar + +RUN set -ex && \ + apt-get update &&\ + TERM=xterm DEBIAN_FRONTEND=noninteractive apt-get install --yes --no-install-recommends unzip wget && \ + wget -qO /tmp/traccar.zip https://github.com/traccar/traccar/releases/download/v$TRACCAR_VERSION/traccar-other-$TRACCAR_VERSION.zip && \ + unzip -qo /tmp/traccar.zip -d /opt/traccar && \ + apt-get autoremove --yes unzip wget && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* + +ENTRYPOINT ["java", "-Xms512m", "-Xmx512m", "-Djava.net.preferIPv4Stack=true"] + +CMD ["-jar", "tracker-server.jar", "conf/traccar.xml"] diff --git a/README.md b/README.md index f83da9f..8688044 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,36 @@ Traccar in Docker --- -Traccar GPS Tracking System in Docker image. +**Traccar GPS Tracking System in Docker image.** Official website: -DockerHub image: +DockerHub image: +Maintainer: [Maxim Zalysin](https://github.com/magna-z) -[![](https://images.microbadger.com/badges/version/traccar/traccar:4.11.svg)](https://microbadger.com/images/traccar/traccar:4.11) -[![](https://images.microbadger.com/badges/image/traccar/traccar:4.11.svg)](https://microbadger.com/images/traccar/traccar:4.11) - -### Available tags: -- **4.11-alpine**, **4-alpine**, **alpine**, **4.11**, **4**, **latest** -- **4.11-debian**, **4-debian**, **debian** +## Available tags: +#### 4.X +- **4.11-alpine**, **4-alpine**, **alpine**, **4.11**, **4**, **latest** ![](https://img.shields.io/microbadger/layers/traccar/traccar/alpine) ![](https://img.shields.io/docker/image-size/traccar/traccar/alpine) +- **4.11-debian**, **4-debian**, **debian** ![](https://img.shields.io/microbadger/layers/traccar/traccar/debian) ![](https://img.shields.io/docker/image-size/traccar/traccar/debian) +- **4.11-ubuntu**, **4-ubuntu**, **ubuntu** ![](https://img.shields.io/microbadger/layers/traccar/traccar/ubuntu) ![](https://img.shields.io/docker/image-size/traccar/traccar/ubuntu) - **4.10-alpine**, **4.10** - **4.10-debian** - **4.9-alpine**, **4.9** - **4.9-debian** -- **4.8-alpine**, **4.8** -- **4.8-debian** -- **4.7-alpine**, **4.7** -- **4.7-debian** -- **4.6-alpine**, **4.6** -- **4.6-debian** -- **4.5-alpine**, **4.5** -- **4.5-debian** -- **4.4-alpine**, **4.4** -- **4.4-debian** -- **4.3-alpine**, **4.3** -- **4.3-debian** -- **4.2-alpine**, **4.2** -- **4.2-debian** -- **4.1-alpine**, **4.1** -- **4.1-debian** +- ... - **4.0-alpine**, **4.0** - **4.0-debian** +#### 3.X - **3.17-alpine**, **3.17** - **3.17-debian** - **3.16-alpine**, **3.16** - **3.16-debian** -### Container create example: +## Available multi-platform images: +**Alpine based**: linux/amd64, linux/386, linux/arm/v6 +**Debian based**: linux/amd64 +**Ubuntu based**: linux/amd64, linux/arm/v7, linux/arm64/v8 + +## Container create example: 1. **Create work directories:** ```bash mkdir -p /var/docker/traccar/logs @@ -70,14 +61,12 @@ DockerHub image: traccar/traccar:latest ``` -### Database -The default when executing the above `docker run` command is an internal H2 database but this should only be for basic use. - -The `docker run` command also doesn't create a mount point on the host for the data folder which will cause the database to be lost when the container is recreated. This point can be mitigated by adding the line `-v /var/docker/traccar/data:/opt/traccar/data:rw \` after `-v /var/docker/traccar/traccar.xml:/opt/traccar/conf/traccar.xml:ro \` but it will still be using the H2 database. - -The **recommended solution** for production use is to link to an external MySQL database and update the configuration .xml file according to the [Traccar MySQL documentation](https://www.traccar.org/mysql/) and using the `docker run` command as-is. +## Database +The default when executing the above `docker run` command is an internal H2 database but this should only be for basic use. +The `docker run` command also doesn't create a mount point on the host for the data folder which will cause the database to be lost when the container is recreated. This point can be mitigated by adding the line `-v /var/docker/traccar/data:/opt/traccar/data:rw \` after `-v /var/docker/traccar/traccar.xml:/opt/traccar/conf/traccar.xml:ro \` but it will still be using the H2 database. +The **recommended solution** for production use is to link to an external MySQL database and update the configuration `.xml`-file according to the [Traccar MySQL documentation](https://www.traccar.org/mysql/) and using the `docker run` command as-is. -### Default JVM options: +## Default JVM options: - -Xms512m - -Xmx512m - -Djava.net.preferIPv4Stack=true From 1be2a79a6b282c862ec0a537b2f490d141cb9670 Mon Sep 17 00:00:00 2001 From: Maxim Zalysin Date: Thu, 7 Jan 2021 21:27:45 +0300 Subject: [PATCH 2/3] Fix GitHub Actions workflow for multi-platform build --- .github/workflows/build-push.yml | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index 56728b4..d3db3e0 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -3,6 +3,8 @@ name: Build and push docker images env: DOCKERHUB_REPOSITORY: traccar/traccar + DOCKERHUB_IMAGE_TAGS: + DOCKERHUB_IMAGE_EXTEND_PLATFORMS: on: push: @@ -10,12 +12,17 @@ on: - master - v[0-9]+.[0-9]+ +defaults: + run: + shell: bash + jobs: docker-build-push: name: Build and push docker images runs-on: ubuntu-20.04 strategy: matrix: + os: [alpine, debian, ubuntu] platform: - os: alpine arch: linux/amd64,linux/386,linux/arm/v6 @@ -36,28 +43,34 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Set environment DOCKERHUB_IMAGE_TAGS on master - if: github.ref == 'refs/heads/master' && matrix.platform.os == 'alpine' + if: github.ref == 'refs/heads/master' && matrix.os == 'alpine' run: echo "DOCKERHUB_IMAGE_TAGS=$DOCKERHUB_REPOSITORY:latest" >> $GITHUB_ENV - name: Set environment DOCKERHUB_IMAGE_TAGS if: github.ref != 'refs/heads/master' - shell: bash run: | _BRANCH=${GITHUB_REF##*/} _VERSION=${_BRANCH#v*} _MAJOR_VERSION=${_VERSION%.*} - _DOCKERHUB_IMAGE_TAGS="$DOCKERHUB_REPOSITORY:$_VERSION-${{ matrix.platform.os }}" - _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:$_MAJOR_VERSION-${{ matrix.platform.os }}" - _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:${{ matrix.platform.os }}" - if [ "${{ matrix.platform.os }}" == "alpine" ]; then + _DOCKERHUB_IMAGE_TAGS="$DOCKERHUB_REPOSITORY:$_VERSION-${{ matrix.os }}" + _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:$_MAJOR_VERSION-${{ matrix.os }}" + _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:${{ matrix.os }}" + if [ "${{ matrix.os }}" == "alpine" ]; then _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:$_VERSION" _DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:$_MAJOR_VERSION" fi echo "DOCKERHUB_IMAGE_TAGS=$_DOCKERHUB_IMAGE_TAGS" >> $GITHUB_ENV + - name: Set environment DOCKERHUB_IMAGE_EXTEND_PLATFORMS + run: | + if [ "${{ matrix.os }}" == "alpine" ]; then + echo "DOCKERHUB_IMAGE_EXTEND_PLATFORMS=,linux/386,linux/arm/v6" >> $GITHUB_ENV + elif [ "${{ matrix.os }}" == "ubuntu" ]; then + echo "DOCKERHUB_IMAGE_EXTEND_PLATFORMS=,linux/arm/v7,linux/arm64/v8" >> $GITHUB_ENV + fi - name: Build and push if: env.DOCKERHUB_IMAGE_TAGS != '' uses: docker/build-push-action@v2 with: - file: Dockerfile.${{ matrix.platform.os }} + file: Dockerfile.${{ matrix.os }} tags: ${{ env.DOCKERHUB_IMAGE_TAGS }} - platforms: matrix.platform.arch + platforms: linux/amd64${{ env.DOCKERHUB_IMAGE_EXTEND_PLATFORMS }} push: true From 69079926b6b2630c45d2a83def1876d38033862b Mon Sep 17 00:00:00 2001 From: Maxim Zalysin Date: Thu, 7 Jan 2021 21:29:20 +0300 Subject: [PATCH 3/3] 2nd fix GitHub Actions workflow for multi-platform build --- .github/workflows/build-push.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index d3db3e0..edf9bc3 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -23,13 +23,6 @@ jobs: strategy: matrix: os: [alpine, debian, ubuntu] - platform: - - os: alpine - arch: linux/amd64,linux/386,linux/arm/v6 - - os: debian - arch: linux/amd64 - - os: ubuntu - arch: linux/amd64,linux/arm/v7,linux/arm64/v8 steps: - name: Checkout uses: actions/checkout@v2