vfedotovs / sslv_web_scraper

ss.lv web scraping app helps automate information scraping and filtering from classifieds and emails results and stores scraped data in database
GNU General Public License v3.0
5 stars 3 forks source link

BUG(Makefile): make up pulls only amd64 architecture web service image and after starting containers on arm64 infrastructure web container fails #276

Open vfedotovs opened 1 week ago

vfedotovs commented 1 week ago

Web Scraper version checks

Reproducible Example

Affected version: 1.5.3

TBC

Issue Description

When repository is cloned to x86 or amd64 architecture deploy of web service works as expected but repository is cloned to arm64 architecture deploy of web service deploys amd64 web service

Expected Behavior

It Makefile should do pre-check of architecture and deploy matching architecture docker images

vfedotovs commented 1 week ago

Proposed solution perform infra architecture pre-check in Makefile

  1. [ ] Create 2 yaml files for each architecture amd64 and arm deployment
  2. [ ] Update Makefile to perform pre-check and deploy correct architecture images

Example of one architecture file docker-compose.amd64.yml:

version: '3'
services:
  web:
    image: yourdockerhubusername/yourapp:latest-amd64
    ports:
      - "80:8501"

start.sh script example

#!/bin/bash

# Function to detect the architecture
detect_architecture() {
  local arch

  if [[ "$(uname)" == "Darwin" ]]; then
    # Check if running under Rosetta
    if [[ "$(sysctl -n sysctl.proc_translated)" == "1" ]]; then
      arch="arm64"  # Assume M1 if running under Rosetta
    else
      arch=$(uname -m)
    fi
  else
    arch=$(uname -m)
  fi

  echo $arch
}

# Detect the architecture
ARCH=$(detect_architecture)

# Set the appropriate Docker Compose file based on the architecture
if [ "$ARCH" == "x86_64" ]; then
    COMPOSE_FILE="docker-compose.amd64.yml"
elif [[ "$ARCH" == "armv7l" || "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then
    COMPOSE_FILE="docker-compose.arm.yml"
else
    echo "Unsupported architecture: $ARCH"
    exit 1
fi

# Pull and start the appropriate containers
docker-compose -f $COMPOSE_FILE pull
docker-compose -f $COMPOSE_FILE up -d

Here is Makefile example

# Detect the architecture
detect_architecture := $(shell uname -m)
os_type := $(shell uname)

ifeq ($(os_type), Darwin)
    is_rosetta := $(shell sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)
    ifeq ($(is_rosetta), 1)
        detect_architecture := arm64
    endif
endif

# Set the appropriate Docker Compose file based on the architecture
ifeq ($(detect_architecture), x86_64)
    COMPOSE_FILE := docker-compose.amd64.yml
else ifeq ($(detect_architecture), arm64)
    COMPOSE_FILE := docker-compose.arm.yml
else ifeq ($(detect_architecture), aarch64)
    COMPOSE_FILE := docker-compose.arm.yml
else ifeq ($(detect_architecture), armv7l)
    COMPOSE_FILE := docker-compose.arm.yml
else
    $(error Unsupported architecture: $(detect_architecture))
endif

# Define targets
.PHONY: all pull up

all: pull up

pull:
    @echo "Pulling images for $(detect_architecture) using $(COMPOSE_FILE)"
    docker-compose -f $(COMPOSE_FILE) pull

up:
    @echo "Starting containers for $(detect_architecture) using $(COMPOSE_FILE)"
    docker-compose -f $(COMPOSE_FILE) up -d