From 21df39553e7d28d4a1aa23fd5e000ebe121c009d Mon Sep 17 00:00:00 2001 From: Jan Cizmar Date: Fri, 12 Dec 2025 16:38:41 +0100 Subject: [PATCH 1/7] chore: Release CLI as a docker image --- .github/workflows/release.yml | 14 +++ Dockerfile | 38 +++++++ HACKING.md | 25 +++++ README.md | 16 +++ scripts/build-docker.sh | 181 ++++++++++++++++++++++++++++++++++ 5 files changed, 274 insertions(+) create mode 100644 Dockerfile create mode 100755 scripts/build-docker.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index de481a72..0cc6e3b7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,6 +37,20 @@ jobs: - name: Build the CLI run: npm run build + + - name: Extract version from package.json + id: package-version + run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + + - name: Build and push Docker image + run: ./scripts/build-docker.sh latest linux/amd64,linux/arm64 push + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + VERSION: ${{ steps.package-version.outputs.VERSION }} + GITHUB_SHA: ${{ github.sha }} + BUILD_DATE: ${{ github.event.head_commit.timestamp }} + - name: Run npm release run: npm run release env: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..1928b867 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# Use Node.js 18 Alpine for smaller image size +FROM node:22-alpine + +# Set working directory +WORKDIR /app + +# Copy package.json and package-lock.json first for better Docker layer caching +COPY package*.json ./ + +# Install all dependencies (including dev dependencies needed by the built code) +RUN npm ci && npm cache clean --force + +# Copy built application files (as specified in package.json "files" section) +COPY dist/ ./dist/ +COPY textmate/ ./textmate/ +COPY extractor.d.ts ./ +COPY schema.json ./ +COPY README.md ./ +COPY LICENSE ./ + +# Copy node_modules for runtime dependencies +COPY node_modules/ ./node_modules/ + +# Make the CLI binary executable +RUN chmod +x ./dist/cli.js + +# Create a non-root user for security +RUN addgroup -g 1001 -S tolgee && \ + adduser -S tolgee -u 1001 + +# Switch to non-root user +USER tolgee + +# Set the entrypoint to the CLI binary +ENTRYPOINT ["node", "./dist/cli.js"] + +# Default command shows help +CMD ["--help"] diff --git a/HACKING.md b/HACKING.md index 54ca79ab..3e961eef 100644 --- a/HACKING.md +++ b/HACKING.md @@ -47,6 +47,31 @@ TOLGEE_TEST_BACKEND_URL=http://localhost:8080 npm run test:e2e When this environment variable is set, the Docker backend will not be started, and tests will use the specified URL instead. +## Building Docker Images + +The project includes Docker support for containerized deployment. The Docker setup consists of: + +- `Dockerfile`: Multi-stage build configuration using Node.js 22 Alpine +- `scripts/build-docker.sh`: Comprehensive build script with multi-platform support + +### Prerequisites + +- Docker installed and running +- For multi-platform builds: Docker Buildx +- For pushing images: Docker Hub credentials + +### Building Docker Images + +The `scripts/build-docker.sh` script provides several build options: + +**Basic build (current platform only):** + +```bash +./scripts/build-docker.sh +``` + +More information about possible build options is documented in the `build-docker.sh`. + ## Code & internals overview ### Command parsing diff --git a/README.md b/README.md index af820972..55279df1 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,22 @@ pnpm add --global @tolgee/cli See our [documentation](https://tolgee.io/tolgee-cli/installation) for more information. +### Docker Installation +Alternatively, you can use the Docker image: + +```sh +# Pull the latest image +docker pull tolgee/cli:latest + +# Run directly +docker run --rm tolgee/cli:latest --help + +# Create an alias for easier usage +alias tolgee="docker run --rm -v \$(pwd):/workspace -w /workspace tolgee/cli:latest" +``` + +The Docker images are available on [Docker Hub](https://hub.docker.com/r/tolgee/cli) and support multiple platforms (linux/amd64, linux/arm64). + ## Usage Once installed, you'll have access to the `tolgee` command. Run `tolgee help` to see all the supported commands, their options and arguments. diff --git a/scripts/build-docker.sh b/scripts/build-docker.sh new file mode 100755 index 00000000..804763df --- /dev/null +++ b/scripts/build-docker.sh @@ -0,0 +1,181 @@ +#!/bin/bash + +# Build Docker image for Tolgee CLI +# Usage: +# ./scripts/build-docker.sh [tag] [platform] [push] +# +# Examples: +# ./scripts/build-docker.sh # Build for current platform with default tag +# ./scripts/build-docker.sh latest # Build for current platform with specific tag +# ./scripts/build-docker.sh latest linux/arm64 # Build for specific single platform (available locally) +# ./scripts/build-docker.sh latest linux/amd64,linux/arm64 # Multi-platform build (NOT available locally) +# ./scripts/build-docker.sh latest linux/amd64,linux/arm64 push # Multi-platform build and push +# +# Environment variables for push: +# DOCKERHUB_USERNAME - Docker Hub username +# DOCKERHUB_TOKEN - Docker Hub token/password +# VERSION - Version for additional tagging (optional) +# +# Note: Multi-platform builds are stored in buildx cache and not available locally. +# To run the image locally after a multi-platform build, either: +# 1. Build for your current platform only (e.g., linux/arm64 on Apple Silicon) +# 2. Push the multi-platform image to a registry and pull it + +set -e + +# Default values +TAG=${1:-"dev"} +PLATFORM=${2:-""} +PUSH=${3:-""} +IMAGE_NAME="tolgee/cli" + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +echo -e "${GREEN}Building Tolgee CLI Docker image...${NC}" +echo "Tag: ${TAG}" +echo "Image: ${IMAGE_NAME}:${TAG}" + +# Check if Docker is running +if ! docker info > /dev/null 2>&1; then + echo -e "${RED}Error: Docker is not running. Please start Docker and try again.${NC}" + exit 1 +fi + +# Docker login if push is requested +if [ "$PUSH" = "push" ]; then + if [ -z "$DOCKERHUB_USERNAME" ] || [ -z "$DOCKERHUB_TOKEN" ]; then + echo -e "${RED}Error: DOCKERHUB_USERNAME and DOCKERHUB_TOKEN environment variables are required for push.${NC}" + exit 1 + fi + echo -e "${GREEN}Logging in to Docker Hub...${NC}" + echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin +fi + +# Ensure we have the built files +if [ ! -d "dist" ]; then + echo -e "${YELLOW}Warning: dist directory not found. Building the CLI first...${NC}" + npm run build +fi + +# Prepare tags +TAGS="-t ${IMAGE_NAME}:${TAG}" +if [ -n "$VERSION" ] && [ "$TAG" = "latest" ]; then + TAGS="$TAGS -t ${IMAGE_NAME}:${VERSION}" +fi + +# Prepare labels +LABELS="" +if [ "$PUSH" = "push" ]; then + LABELS="--label org.opencontainers.image.title=Tolgee CLI" + LABELS="$LABELS --label org.opencontainers.image.description=A tool to interact with the Tolgee Platform through CLI" + LABELS="$LABELS --label org.opencontainers.image.url=https://github.com/tolgee/tolgee-cli" + LABELS="$LABELS --label org.opencontainers.image.source=https://github.com/tolgee/tolgee-cli" + LABELS="$LABELS --label org.opencontainers.image.licenses=MIT" + if [ -n "$VERSION" ]; then + LABELS="$LABELS --label org.opencontainers.image.version=${VERSION}" + fi + if [ -n "$GITHUB_SHA" ]; then + LABELS="$LABELS --label org.opencontainers.image.revision=${GITHUB_SHA}" + fi + if [ -n "$BUILD_DATE" ]; then + LABELS="$LABELS --label org.opencontainers.image.created=${BUILD_DATE}" + fi +fi + +# Build command +BUILD_CMD="docker build $TAGS $LABELS" + +if [ -n "$PLATFORM" ]; then + echo "Platform(s): ${PLATFORM}" + # For multi-platform builds, we need buildx + BUILD_CMD="docker buildx build --platform ${PLATFORM} $TAGS $LABELS" + + # Check if buildx is available + if ! docker buildx version > /dev/null 2>&1; then + echo -e "${RED}Error: Docker buildx is required for multi-platform builds.${NC}" + echo "Please install Docker buildx or build for single platform." + exit 1 + fi + + # Create builder if it doesn't exist + if ! docker buildx inspect tolgee-builder > /dev/null 2>&1; then + echo -e "${YELLOW}Creating multi-platform builder...${NC}" + docker buildx create --name tolgee-builder --use + else + docker buildx use tolgee-builder + fi + + # Check if this is a single platform build that can be loaded locally + PLATFORM_COUNT=$(echo "$PLATFORM" | tr ',' '\n' | wc -l) + if [ "$PLATFORM_COUNT" -eq 1 ] && [ "$PUSH" != "push" ]; then + # Single platform - we can load it to local Docker daemon + BUILD_CMD="${BUILD_CMD} --load" + echo -e "${GREEN}Single platform build - image will be available locally after build.${NC}" + elif [ "$PUSH" = "push" ]; then + # Push mode - add push flag + BUILD_CMD="${BUILD_CMD} --push" + echo -e "${GREEN}Build and push mode enabled.${NC}" + else + # Multi-platform build - cannot load to local Docker daemon + echo -e "${YELLOW}Multi-platform build - image will NOT be available locally.${NC}" + echo -e "${YELLOW}To run locally, build for your current platform only or push to a registry.${NC}" + fi +elif [ "$PUSH" = "push" ]; then + # Regular build with push - we need to build and then push + echo -e "${GREEN}Build and push mode enabled for single architecture.${NC}" +fi + +BUILD_CMD="${BUILD_CMD} ." + +echo -e "${GREEN}Running: ${BUILD_CMD}${NC}" +eval $BUILD_CMD + +if [ "$PUSH" = "push" ] && [ -z "$PLATFORM" ]; then + # For regular builds, we need to push separately + echo -e "${GREEN}Pushing images to registry...${NC}" + docker push ${IMAGE_NAME}:${TAG} + if [ -n "$VERSION" ] && [ "$TAG" = "latest" ]; then + docker push ${IMAGE_NAME}:${VERSION} + fi +fi + +if [ "$PUSH" = "push" ]; then + echo -e "${GREEN}✓ Docker image built and pushed successfully!${NC}" +else + echo -e "${GREEN}✓ Docker image built successfully!${NC}" +fi + +# Show appropriate run instruction based on build type +if [ -n "$PLATFORM" ]; then + PLATFORM_COUNT=$(echo "$PLATFORM" | tr ',' '\n' | wc -l) + if [ "$PLATFORM_COUNT" -eq 1 ]; then + # Single platform - image is available locally + echo -e "${GREEN}Run with: docker run --rm ${IMAGE_NAME}:${TAG}${NC}" + else + # Multi-platform - image is NOT available locally + echo -e "${YELLOW}Multi-platform build completed. Image is not available locally.${NC}" + echo -e "${YELLOW}To run locally: build for your platform only or pull from registry after push.${NC}" + fi +else + # Default build for current platform - always available locally + echo -e "${GREEN}Run with: docker run --rm ${IMAGE_NAME}:${TAG}${NC}" +fi + +# Show image info +echo -e "\n${YELLOW}Image information:${NC}" +if [ -n "$PLATFORM" ]; then + PLATFORM_COUNT=$(echo "$PLATFORM" | tr ',' '\n' | wc -l) + if [ "$PLATFORM_COUNT" -eq 1 ]; then + echo "Single-platform image built and loaded locally." + docker images ${IMAGE_NAME}:${TAG} + else + echo "Multi-platform image built. Use 'docker buildx imagetools inspect ${IMAGE_NAME}:${TAG}' to see details." + echo "Note: Multi-platform images are not available locally. Build for your current platform to run locally." + fi +else + docker images ${IMAGE_NAME}:${TAG} +fi From 55c29e56994a5094dbf8d4f4f424b6556b1b5b07 Mon Sep 17 00:00:00 2001 From: Jan Cizmar Date: Thu, 18 Dec 2025 11:07:06 +0100 Subject: [PATCH 2/7] fix: Make the image smaller --- Dockerfile | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1928b867..ea7a36ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,52 @@ -# Use Node.js 18 Alpine for smaller image size -FROM node:22-alpine +# Multi-stage Docker build for Tolgee CLI +# Stage 1: Build stage with dev dependencies +FROM node:18-alpine AS builder # Set working directory WORKDIR /app -# Copy package.json and package-lock.json first for better Docker layer caching +# Copy package files first for better Docker layer caching COPY package*.json ./ -# Install all dependencies (including dev dependencies needed by the built code) +# Install ALL dependencies (including dev dependencies needed for building) RUN npm ci && npm cache clean --force -# Copy built application files (as specified in package.json "files" section) -COPY dist/ ./dist/ +# Copy source files +COPY src/ ./src/ +COPY scripts/ ./scripts/ +COPY tsconfig*.json ./ +COPY eslint.config.js ./ + +# Copy additional files needed for build COPY textmate/ ./textmate/ COPY extractor.d.ts ./ COPY schema.json ./ + +# Build the CLI +RUN npm run build + +# Stage 2: Production stage with only runtime dependencies +FROM node:18-alpine AS production + +# Set working directory +WORKDIR /app + +# Copy package files first for better Docker layer caching +COPY package*.json ./ + +# Install ONLY production dependencies +RUN npm ci --only=production && npm cache clean --force + +# Copy built application files from builder stage +COPY --from=builder /app/dist/ ./dist/ +COPY --from=builder /app/textmate/ ./textmate/ +COPY --from=builder /app/extractor.d.ts ./ +COPY --from=builder /app/schema.json ./ + +# Copy documentation files COPY README.md ./ COPY LICENSE ./ -# Copy node_modules for runtime dependencies -COPY node_modules/ ./node_modules/ - # Make the CLI binary executable RUN chmod +x ./dist/cli.js From 5e88d34011c34119365db38b5efdc4d34c01cdeb Mon Sep 17 00:00:00 2001 From: Jan Cizmar Date: Thu, 18 Dec 2025 13:25:10 +0100 Subject: [PATCH 3/7] chore: Fix CR issues, try to publish the image prerelease --- .github/workflows/release.yml | 26 ++++++++-------- Dockerfile | 4 +-- HACKING.md | 2 +- scripts/build-docker.sh | 58 ++++++++++++++++++++--------------- 4 files changed, 49 insertions(+), 41 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0cc6e3b7..a90f3921 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,7 @@ on: types: - completed push: - branches: [ next, prerelease ] + branches: [ next, prerelease, jancizmar/release-docker-image ] # This part sets up the Trusted Publishers for npm via GitHub Actions, # that's why we don't need to set up the token manually @@ -38,9 +38,18 @@ jobs: - name: Build the CLI run: npm run build + - name: Run npm release + run: npm run release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GIT_AUTHOR_NAME: Tolgee Machine + GIT_AUTHOR_EMAIL: machine@tolgee.io + GIT_COMMITTER_NAME: Tolgee Machine + GIT_COMMITTER_EMAIL: machine@tolgee.io + - name: Extract version from package.json id: package-version - run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + run: echo "VERSION=$(node -p 'require("./package.json").version')" >> "$GITHUB_OUTPUT" - name: Build and push Docker image run: ./scripts/build-docker.sh latest linux/amd64,linux/arm64 push @@ -48,14 +57,5 @@ jobs: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} VERSION: ${{ steps.package-version.outputs.VERSION }} - GITHUB_SHA: ${{ github.sha }} - BUILD_DATE: ${{ github.event.head_commit.timestamp }} - - - name: Run npm release - run: npm run release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GIT_AUTHOR_NAME: Tolgee Machine - GIT_AUTHOR_EMAIL: machine@tolgee.io - GIT_COMMITTER_NAME: Tolgee Machine - GIT_COMMITTER_EMAIL: machine@tolgee.io + GITHUB_SHA: ${{ github.event.workflow_run.head_sha }} + BUILD_DATE: ${{ github.event.workflow_run.head_commit.timestamp }} diff --git a/Dockerfile b/Dockerfile index ea7a36ca..0fa32d6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # Multi-stage Docker build for Tolgee CLI # Stage 1: Build stage with dev dependencies -FROM node:18-alpine AS builder +FROM node:24-alpine AS builder # Set working directory WORKDIR /app @@ -26,7 +26,7 @@ COPY schema.json ./ RUN npm run build # Stage 2: Production stage with only runtime dependencies -FROM node:18-alpine AS production +FROM node:24-alpine AS production # Set working directory WORKDIR /app diff --git a/HACKING.md b/HACKING.md index 3e961eef..029c1975 100644 --- a/HACKING.md +++ b/HACKING.md @@ -5,7 +5,7 @@ to get some work done. ## Toolchain -To work on this project, you will just need Node 16+ (and Docker to run tests). We use `npm` to manage dependencies, +To work on this project, you will just need Node 22+ (and Docker to run tests). We use `npm` to manage dependencies, and [prettier](https://github.com/prettier/prettier) to lint our code. ## Scripts diff --git a/scripts/build-docker.sh b/scripts/build-docker.sh index 804763df..c054146b 100755 --- a/scripts/build-docker.sh +++ b/scripts/build-docker.sh @@ -21,7 +21,7 @@ # 1. Build for your current platform only (e.g., linux/arm64 on Apple Silicon) # 2. Push the multi-platform image to a registry and pull it -set -e +set -euo pipefail # Default values TAG=${1:-"dev"} @@ -47,7 +47,7 @@ fi # Docker login if push is requested if [ "$PUSH" = "push" ]; then - if [ -z "$DOCKERHUB_USERNAME" ] || [ -z "$DOCKERHUB_TOKEN" ]; then + if [ -z "${DOCKERHUB_USERNAME:-}" ] || [ -z "${DOCKERHUB_TOKEN:-}" ]; then echo -e "${RED}Error: DOCKERHUB_USERNAME and DOCKERHUB_TOKEN environment variables are required for push.${NC}" exit 1 fi @@ -62,37 +62,45 @@ if [ ! -d "dist" ]; then fi # Prepare tags -TAGS="-t ${IMAGE_NAME}:${TAG}" -if [ -n "$VERSION" ] && [ "$TAG" = "latest" ]; then - TAGS="$TAGS -t ${IMAGE_NAME}:${VERSION}" +TAGS=( -t "${IMAGE_NAME}:${TAG}" ) +if [ -n "${VERSION:-}" ] && [ "$TAG" = "latest" ]; then + TAGS+=( -t "${IMAGE_NAME}:${VERSION}" ) fi # Prepare labels -LABELS="" +LABELS=() if [ "$PUSH" = "push" ]; then - LABELS="--label org.opencontainers.image.title=Tolgee CLI" - LABELS="$LABELS --label org.opencontainers.image.description=A tool to interact with the Tolgee Platform through CLI" - LABELS="$LABELS --label org.opencontainers.image.url=https://github.com/tolgee/tolgee-cli" - LABELS="$LABELS --label org.opencontainers.image.source=https://github.com/tolgee/tolgee-cli" - LABELS="$LABELS --label org.opencontainers.image.licenses=MIT" - if [ -n "$VERSION" ]; then - LABELS="$LABELS --label org.opencontainers.image.version=${VERSION}" + LABELS+=( --label "org.opencontainers.image.title=Tolgee CLI" ) + LABELS+=( --label "org.opencontainers.image.description=A tool to interact with the Tolgee Platform through CLI" ) + LABELS+=( --label "org.opencontainers.image.url=https://github.com/tolgee/tolgee-cli" ) + LABELS+=( --label "org.opencontainers.image.source=https://github.com/tolgee/tolgee-cli" ) + LABELS+=( --label "org.opencontainers.image.licenses=MIT" ) + if [ -n "${VERSION:-}" ]; then + LABELS+=( --label "org.opencontainers.image.version=${VERSION}" ) fi - if [ -n "$GITHUB_SHA" ]; then - LABELS="$LABELS --label org.opencontainers.image.revision=${GITHUB_SHA}" + if [ -n "${GITHUB_SHA:-}" ]; then + LABELS+=( --label "org.opencontainers.image.revision=${GITHUB_SHA}" ) fi - if [ -n "$BUILD_DATE" ]; then - LABELS="$LABELS --label org.opencontainers.image.created=${BUILD_DATE}" + if [ -n "${BUILD_DATE:-}" ]; then + LABELS+=( --label "org.opencontainers.image.created=${BUILD_DATE}" ) fi fi # Build command -BUILD_CMD="docker build $TAGS $LABELS" +BUILD_CMD=( docker build ) +BUILD_CMD+=( "${TAGS[@]}" ) +if [ ${#LABELS[@]} -gt 0 ]; then + BUILD_CMD+=( "${LABELS[@]}" ) +fi if [ -n "$PLATFORM" ]; then echo "Platform(s): ${PLATFORM}" # For multi-platform builds, we need buildx - BUILD_CMD="docker buildx build --platform ${PLATFORM} $TAGS $LABELS" + BUILD_CMD=( docker buildx build --platform "${PLATFORM}" ) + BUILD_CMD+=( "${TAGS[@]}" ) + if [ ${#LABELS[@]} -gt 0 ]; then + BUILD_CMD+=( "${LABELS[@]}" ) + fi # Check if buildx is available if ! docker buildx version > /dev/null 2>&1; then @@ -113,11 +121,11 @@ if [ -n "$PLATFORM" ]; then PLATFORM_COUNT=$(echo "$PLATFORM" | tr ',' '\n' | wc -l) if [ "$PLATFORM_COUNT" -eq 1 ] && [ "$PUSH" != "push" ]; then # Single platform - we can load it to local Docker daemon - BUILD_CMD="${BUILD_CMD} --load" + BUILD_CMD+=( --load ) echo -e "${GREEN}Single platform build - image will be available locally after build.${NC}" elif [ "$PUSH" = "push" ]; then # Push mode - add push flag - BUILD_CMD="${BUILD_CMD} --push" + BUILD_CMD+=( --push ) echo -e "${GREEN}Build and push mode enabled.${NC}" else # Multi-platform build - cannot load to local Docker daemon @@ -129,16 +137,16 @@ elif [ "$PUSH" = "push" ]; then echo -e "${GREEN}Build and push mode enabled for single architecture.${NC}" fi -BUILD_CMD="${BUILD_CMD} ." +BUILD_CMD+=( . ) -echo -e "${GREEN}Running: ${BUILD_CMD}${NC}" -eval $BUILD_CMD +echo -e "${GREEN}Running:${NC} ${BUILD_CMD[*]}" +"${BUILD_CMD[@]}" if [ "$PUSH" = "push" ] && [ -z "$PLATFORM" ]; then # For regular builds, we need to push separately echo -e "${GREEN}Pushing images to registry...${NC}" docker push ${IMAGE_NAME}:${TAG} - if [ -n "$VERSION" ] && [ "$TAG" = "latest" ]; then + if [ -n "${VERSION:-}" ] && [ "$TAG" = "latest" ]; then docker push ${IMAGE_NAME}:${VERSION} fi fi From 732c58e3d8edd75985dffd95d9e817e6b14ac1dd Mon Sep 17 00:00:00 2001 From: Jan Cizmar Date: Thu, 18 Dec 2025 14:39:01 +0100 Subject: [PATCH 4/7] chore: Try if version was released before releasing docker version --- .github/workflows/release.yml | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a90f3921..3fe77b16 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,7 @@ on: types: - completed push: - branches: [ next, prerelease, jancizmar/release-docker-image ] + branches: [ next, prerelease ] # This part sets up the Trusted Publishers for npm via GitHub Actions, # that's why we don't need to set up the token manually @@ -38,6 +38,10 @@ jobs: - name: Build the CLI run: npm run build + - name: Store version before release + id: version-before + run: echo "VERSION=$(node -p 'require("./package.json").version')" >> "$GITHUB_OUTPUT" + - name: Run npm release run: npm run release env: @@ -47,15 +51,27 @@ jobs: GIT_COMMITTER_NAME: Tolgee Machine GIT_COMMITTER_EMAIL: machine@tolgee.io - - name: Extract version from package.json - id: package-version + - name: Extract version after release + id: version-after run: echo "VERSION=$(node -p 'require("./package.json").version')" >> "$GITHUB_OUTPUT" + - name: Check if version was released + id: version-check + run: | + if [ "${{ steps.version-before.outputs.VERSION }}" != "${{ steps.version-after.outputs.VERSION }}" ]; then + echo "RELEASED=true" >> "$GITHUB_OUTPUT" + echo "New version released: ${{ steps.version-before.outputs.VERSION }} -> ${{ steps.version-after.outputs.VERSION }}" + else + echo "RELEASED=false" >> "$GITHUB_OUTPUT" + echo "No new version released (version remains ${{ steps.version-before.outputs.VERSION }})" + fi + - name: Build and push Docker image + if: steps.version-check.outputs.RELEASED == 'true' run: ./scripts/build-docker.sh latest linux/amd64,linux/arm64 push env: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - VERSION: ${{ steps.package-version.outputs.VERSION }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_PASSWORD }} + VERSION: ${{ steps.version-after.outputs.VERSION }} GITHUB_SHA: ${{ github.event.workflow_run.head_sha }} BUILD_DATE: ${{ github.event.workflow_run.head_commit.timestamp }} From 4facf48fceacbb94839b61a17c2211ac035b3352 Mon Sep 17 00:00:00 2001 From: Jan Cizmar Date: Thu, 18 Dec 2025 14:51:00 +0100 Subject: [PATCH 5/7] chore: Try if version was released before releasing docker version --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3fe77b16..60bc7e18 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -71,7 +71,7 @@ jobs: run: ./scripts/build-docker.sh latest linux/amd64,linux/arm64 push env: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_PASSWORD }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} VERSION: ${{ steps.version-after.outputs.VERSION }} - GITHUB_SHA: ${{ github.event.workflow_run.head_sha }} - BUILD_DATE: ${{ github.event.workflow_run.head_commit.timestamp }} + GITHUB_SHA: ${{ github.event.workflow_run.head_sha || github.sha }} + BUILD_DATE: ${{ github.event.workflow_run.run_started_at || github.event.workflow_run.head_commit.timestamp }} From 6e101b8e89247b32686d98d475088e1e6eba5e6b Mon Sep 17 00:00:00 2001 From: Jan Cizmar Date: Thu, 18 Dec 2025 14:55:21 +0100 Subject: [PATCH 6/7] chore: Use DOCKERHUB_TOKEN --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 60bc7e18..86d14de4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -71,7 +71,7 @@ jobs: run: ./scripts/build-docker.sh latest linux/amd64,linux/arm64 push env: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_PASSWORD }} VERSION: ${{ steps.version-after.outputs.VERSION }} GITHUB_SHA: ${{ github.event.workflow_run.head_sha || github.sha }} BUILD_DATE: ${{ github.event.workflow_run.run_started_at || github.event.workflow_run.head_commit.timestamp }} From dcbecd13b5ca7e8a42d5ca83356eb7f7ea755dce Mon Sep 17 00:00:00 2001 From: Jan Cizmar Date: Thu, 18 Dec 2025 19:10:11 +0100 Subject: [PATCH 7/7] chore: Remove unused eslint.config.js from Dockerfile --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0fa32d6c..3d7ada61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,6 @@ RUN npm ci && npm cache clean --force COPY src/ ./src/ COPY scripts/ ./scripts/ COPY tsconfig*.json ./ -COPY eslint.config.js ./ # Copy additional files needed for build COPY textmate/ ./textmate/