Files
shopify-ai-backup/Dockerfile

133 lines
4.2 KiB
Docker

# Web-based PowerShell + SST OpenCode terminal
# Builds OpenCode CLI from source during Docker build
FROM ubuntu:24.04 AS opencode-builder
ARG BUN_VERSION=1.3.8
ENV DEBIAN_FRONTEND=noninteractive \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
git \
tar \
xz-utils \
gzip \
unzip \
build-essential \
python3 \
cmake \
&& rm -rf /var/lib/apt/lists/*
# Install Node.js (required for some dependencies)
RUN curl -fsSL -o /tmp/node.tar.xz \
"https://nodejs.org/dist/v20.18.1/node-v20.18.1-linux-x64.tar.xz" \
&& tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 \
&& rm -f /tmp/node.tar.xz
# Install Bun
RUN npm install -g bun@${BUN_VERSION} \
&& bun --version
# Copy OpenCode source
COPY opencode /opt/opencode-src
WORKDIR /opt/opencode-src
# Configure git for any workspace dependencies that use git URLs
RUN git config --global url."https://github.com/".insteadOf "ssh://git@github.com/"
# Install dependencies at root level first (for workspaces)
ENV HUSKY=0
RUN bun install 2>&1
# Build OpenCode CLI - run from root directory where package.json is
WORKDIR /opt/opencode-src
RUN cd packages/opencode && bun run script/build.ts --single 2>&1 || (echo "Build failed, checking logs..." && cat /tmp/build.log 2>/dev/null || echo "No log file" && exit 1)
# Final stage
FROM ubuntu:24.04
ARG PWSH_VERSION=7.4.6
ARG NODE_VERSION=20.18.1
ARG TTYD_VERSION=1.7.7
ENV DEBIAN_FRONTEND=noninteractive \
TERM=xterm-256color \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
wget \
git \
tar \
xz-utils \
gzip \
tini \
libicu-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Node.js
RUN curl -fsSL -o /tmp/node.tar.xz \
"https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" \
&& tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 \
&& ln -sf /usr/local/bin/node /usr/bin/node \
&& ln -sf /usr/local/bin/npm /usr/bin/npm \
&& rm -f /tmp/node.tar.xz
# Install PowerShell
RUN curl -fsSL -o /tmp/powershell.tar.gz \
"https://github.com/PowerShell/PowerShell/releases/download/v${PWSH_VERSION}/powershell-${PWSH_VERSION}-linux-x64.tar.gz" \
&& mkdir -p /opt/microsoft/powershell/7 \
&& tar -xzf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7 \
&& chmod +x /opt/microsoft/powershell/7/pwsh \
&& ln -sf /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh \
&& rm -f /tmp/powershell.tar.gz
# Install ttyd
RUN curl -fsSL -o /usr/local/bin/ttyd \
"https://github.com/tsl0922/ttyd/releases/download/${TTYD_VERSION}/ttyd.x86_64" \
&& chmod +x /usr/local/bin/ttyd
# Copy the built OpenCode binary from builder stage
COPY --from=opencode-builder /opt/opencode-src/packages/opencode/dist/opencode-linux-x64/bin/opencode /usr/local/bin/opencode
RUN chmod +x /usr/local/bin/opencode && opencode --version
# Setup PowerShell profile
RUN mkdir -p /root/.config/powershell
COPY profile/Microsoft.PowerShell_profile.ps1 /root/.config/powershell/Microsoft.PowerShell_profile.ps1
RUN chmod 644 /root/.config/powershell/Microsoft.PowerShell_profile.ps1
# Copy scripts
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
COPY scripts/healthcheck.sh /usr/local/bin/healthcheck.sh
COPY scripts/diagnostic-logger.sh /usr/local/bin/diagnostic-logger.sh
RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/healthcheck.sh /usr/local/bin/diagnostic-logger.sh
# Copy webchat
COPY chat /opt/webchat
RUN cd /opt/webchat && npm install --production && chmod -R 755 /opt/webchat
COPY chat_v2 /opt/webchat_v2
RUN chmod -R 755 /opt/webchat_v2
# Create data directories
RUN mkdir -p /home/web/data \
&& mkdir -p /var/log/shopify-ai \
&& chown -R root:root /home/web/data /var/log/shopify-ai
WORKDIR /home/web/data
EXPOSE 4500
HEALTHCHECK --interval=30s --timeout=15s --start-period=60s --retries=5 \
CMD /usr/local/bin/healthcheck.sh || exit 1
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/entrypoint.sh"]