Skip to content

Commit

Permalink
chore: Update DockerHub workflow to support new platform configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorfdl committed Jun 21, 2024
1 parent 853139c commit 966c709
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 55 deletions.
63 changes: 31 additions & 32 deletions .github/workflows/build-dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
6 changes: 6 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
34 changes: 34 additions & 0 deletions build/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -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"]
14 changes: 13 additions & 1 deletion build/Dockerfile → build/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
55 changes: 33 additions & 22 deletions dockerhub.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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]}
Expand All @@ -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 \
.

0 comments on commit 966c709

Please sign in to comment.