From 966c7094882552fc5f47bb6f155871e28776f262 Mon Sep 17 00:00:00 2001 From: Vitor Lima Date: Fri, 21 Jun 2024 19:34:51 -0300 Subject: [PATCH] chore: Update DockerHub workflow to support new platform configurations --- .github/workflows/build-dockerhub.yml | 63 ++++++++++++------------- Cross.toml | 6 +++ build/Dockerfile.alpine | 34 +++++++++++++ build/{Dockerfile => Dockerfile.debian} | 14 +++++- dockerhub.sh | 55 ++++++++++++--------- 5 files changed, 117 insertions(+), 55 deletions(-) create mode 100644 build/Dockerfile.alpine rename build/{Dockerfile => Dockerfile.debian} (56%) mode change 100644 => 100755 dockerhub.sh diff --git a/.github/workflows/build-dockerhub.yml b/.github/workflows/build-dockerhub.yml index 361c57c..a1af65a 100644 --- a/.github/workflows/build-dockerhub.yml +++ b/.github/workflows/build-dockerhub.yml @@ -17,7 +17,7 @@ jobs: matrix: config: - { platform: linux-amd64, dist: "debian", target: x86_64-unknown-linux-gnu } - # - { platform: linux-arm64-v8, dist: "debian", target: aarch64-unknown-linux-gnu } + - { platform: linux-arm64-v8, dist: "debian", target: aarch64-unknown-linux-gnu } # - { platform: linux-amd64, dist: alpine, target: x86_64-unknown-linux-musl } # - { platform: linux-arm64-v8, dist: alpine, target: aarch64-unknown-linux-musl } environment: PROD @@ -73,8 +73,7 @@ jobs: matrix: include: - { dist: "debian", architecture: "linux/amd64,linux/arm64/v8" } - # - { platform: linux-x64-alpine, os: ubuntu-latest, architecture: linux/amd64 } - # - { platform: linux-arm64-alpine, os: ubuntu-latest, architecture: linux/arm64/v8 } + # - { dist: "alpine", architecture: "linux/amd64,linux/arm64/v8" } steps: - name: Checkout code @@ -89,33 +88,33 @@ jobs: - name: List files run: ls -la build - - name: Ensure tagoio-relay exists - run: | - if [ ! -f build/tagoio-relay ]; then - echo "tagoio-relay not found in build folder" - exit 1 - fi + # - name: Ensure tagoio-relay exists + # run: | + # if [ ! -f build/tagoio-relay ]; then + # echo "tagoio-relay not found in build folder" + # exit 1 + # fi + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - # - name: Set up QEMU - # uses: docker/setup-qemu-action@v3 - - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v3 - - # - name: Cache Docker layers - # uses: actions/cache@v4 - # with: - # path: /tmp/.buildx-cache - # key: ${{ runner.os }}-buildx-${{ github.sha }} - # restore-keys: | - # ${{ runner.os }}-buildx- - - # - name: Login to DockerHub - # uses: docker/login-action@v3 - # with: - # username: ${{ secrets.DOCKERHUB_USERNAME }} - # password: ${{ secrets.DOCKERHUB_TOKEN }} - - # # linux/arm64/v8,linux/amd64 - # - name: Build and deploy images - # run: bash dockerhub.sh ${{ matrix.architecture }} ${{ github.event.inputs.version || github.event.release.tag_name }} + # linux/arm64/v8,linux/amd64 + - name: Build and deploy images + run: bash dockerhub.sh ${{ matrix.dist }} ${{ matrix.architecture }} ${{ github.event.inputs.version || github.event.release.tag_name }} diff --git a/Cross.toml b/Cross.toml index 50a8272..3de12f3 100644 --- a/Cross.toml +++ b/Cross.toml @@ -3,3 +3,9 @@ image = "rustembedded/cross:x86_64-pc-windows-msvc-0.2.1" [target.aarch64-unknown-linux-gnu] image = "ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main" + +[target.x86_64-unknown-linux-musl] +image = "ghcr.io/cross-rs/x86_64-unknown-linux-musl:main" + +[target.aarch64-unknown-linux-musl] +image = "ghcr.io/cross-rs/aarch64-unknown-linux-musl:main" \ No newline at end of file diff --git a/build/Dockerfile.alpine b/build/Dockerfile.alpine new file mode 100644 index 0000000..2f76e0f --- /dev/null +++ b/build/Dockerfile.alpine @@ -0,0 +1,34 @@ +# Install runtime dependencies +FROM alpine:latest +ARG TAGOIO_SOURCE_FOLDER="/tago-io" +ARG TARGETPLATFORM + +# Install necessary packages +RUN apk update && \ + apk add --no-cache openssl build-base netcat-openbsd ca-certificates + + +RUN mkdir -p ${TAGOIO_SOURCE_FOLDER} +WORKDIR ${TAGOIO_SOURCE_FOLDER} + +COPY /alpine-* . + +# Rename the correct executable based on the platform +RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \ + mv alpine-linux-amd64 tagoio-relay; \ + elif [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \ + mv alpine-linux-arm64 tagoio-relay; \ + else \ + echo "Unsupported platform: ${TARGETPLATFORM}"; \ + exit 1; \ + fi + + +# Add execute permissions to the tagoio-relay file +RUN chmod +x tagoio-relay +RUN ./tagoio-relay init + +EXPOSE 3001/tcp + +ENTRYPOINT ["/tago-io/tagoio-relay"] +CMD ["start"] diff --git a/build/Dockerfile b/build/Dockerfile.debian similarity index 56% rename from build/Dockerfile rename to build/Dockerfile.debian index 0065645..db8f618 100644 --- a/build/Dockerfile +++ b/build/Dockerfile.debian @@ -1,6 +1,7 @@ # Install runtime dependencies FROM debian:bookworm-slim ARG TAGOIO_SOURCE_FOLDER="/tago-io" +ARG TARGETPLATFORM RUN apt update RUN apt install -y openssl build-essential netcat-traditional ca-certificates --no-install-recommends @@ -9,7 +10,18 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* RUN mkdir -p ${TAGOIO_SOURCE_FOLDER} WORKDIR ${TAGOIO_SOURCE_FOLDER} -COPY /tagoio-relay . +COPY /debian-* . + +# Rename the correct executable based on the platform +RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \ + mv debian-linux-amd64 tagoio-relay; \ + elif [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \ + mv debian-linux-arm64 tagoio-relay; \ + else \ + echo "Unsupported platform: ${TARGETPLATFORM}"; \ + exit 1; \ + fi + # Add execute permissions to the tagoio-relay file RUN chmod +x tagoio-relay diff --git a/dockerhub.sh b/dockerhub.sh old mode 100644 new mode 100755 index 509bd61..57eecf9 --- a/dockerhub.sh +++ b/dockerhub.sh @@ -1,18 +1,25 @@ #!/bin/bash # Ensure a platform is provided if [ -z "$1" ]; then - echo "Error: No platform provided." + echo "Error: No distribution provided." exit 1 fi # Ensure a version is provided if [ -z "$2" ]; then + echo "Error: No platform provided." + exit 1 +fi + +# Ensure a version is provided +if [ -z "$3" ]; then echo "Error: No version provided." exit 1 fi -PLATFORM=$1 -FULL_VERSION=$2 +DISTRIBUTION=$1 +PLATFORM=$2 +FULL_VERSION=$3 SPLIT=(${FULL_VERSION//./ }) MAJOR=${SPLIT[0]} @@ -35,28 +42,32 @@ if ! [[ "$PATCH" =~ ^[0-9]+$ ]]; then exit 1 fi -# Ensure CARGO_SERVER_SSL_CA, CARGO_SERVER_SSL_CERT, and CARGO_SERVER_SSL_KEY are set -# if [ -z "$CARGO_SERVER_SSL_CA" ] || [ -z "$CARGO_SERVER_SSL_CERT" ] || [ -z "$CARGO_SERVER_SSL_KEY" ]; then -# echo "Error: SSL environment variables are not set." -# exit 1 -# fi +echo "Building for $DISTRIBUTION on $PLATFORM" -# CARGO_SERVER_SSL_CA_BASE64=$(echo "$CARGO_SERVER_SSL_CA" | base64 -w 0) -# CARGO_SERVER_SSL_CERT_BASE64=$(echo "$CARGO_SERVER_SSL_CERT" | base64 -w 0) -# CARGO_SERVER_SSL_KEY_BASE64=$(echo "$CARGO_SERVER_SSL_KEY" | base64 -w 0) +# Construct the tags +if [ "$DISTRIBUTION" == "debian" ]; then + TAGS="--tag tagoio/relay \ + --tag tagoio/relay:${DISTRIBUTION} \ + --tag tagoio/relay:${MAJOR}.${MINOR} \ + --tag tagoio/relay:${MAJOR}.${MINOR}.${PATCH} \ + --tag tagoio/relay:bookworm \ + --tag tagoio/relay:${MAJOR}.${MINOR}-bookworm \ + --tag tagoio/relay:${MAJOR}.${MINOR}.${PATCH}-bookworm" +elif [ "$DISTRIBUTION" == "alpine" ]; then + TAGS="--tag tagoio/relay:${DISTRIBUTION} \ + --tag tagoio/relay:${MAJOR}.${MINOR}-alpine \ + --tag tagoio/relay:${MAJOR}.${MINOR}.${PATCH}-alpine" +else + echo "Error: Unknown distribution." + exit 1 +fi +# Display the tags +echo "Tags to be used: $TAGS" # Debian cd build docker buildx build --push --build-arg TAGORELAY_VERSION=${FULL_VERSION} \ - \ + --file Dockerfile.${DISTRIBUTION} \ --platform ${PLATFORM} \ - --tag tagoio/relay \ - --tag tagoio/relay:debian \ - --tag tagoio/relay:bookworm \ - --tag tagoio/relay:${MAJOR}.${MINOR}-bookworm \ - --tag tagoio/relay:${MAJOR}.${MINOR}.${PATCH}-bookworm \ - --tag tagoio/relay:${MAJOR}.${MINOR} \ - --tag tagoio/relay:${MAJOR}.${MINOR}.${PATCH} \ - . # --build-arg CARGO_SERVER_SSL_CA=${CARGO_SERVER_SSL_CA_BASE64} \ -# --build-arg CARGO_SERVER_SSL_CERT=${CARGO_SERVER_SSL_CERT_BASE64} \ -# --build-arg CARGO_SERVER_SSL_KEY=${CARGO_SERVER_SSL_KEY_BASE64} \ + $TAGS \ + .