From 0dc0c30e32598d52f48724255d1efef28a06518c Mon Sep 17 00:00:00 2001 From: david zhou Date: Mon, 17 Jun 2024 16:36:54 +1000 Subject: [PATCH 1/7] test deploy --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b1d796dc0..b85c063a5 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - component: [client] + component: [client, debugger] steps: - name: Checkout repository uses: actions/checkout@v4 From e79ecac3f77fe1eba266b9b213f076532e683a53 Mon Sep 17 00:00:00 2001 From: david zhou Date: Mon, 17 Jun 2024 16:44:29 +1000 Subject: [PATCH 2/7] allow app to be manually deplopy without merhe --- .github/workflows/docker.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b85c063a5..43a5136a9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,6 +2,14 @@ name: Deploy on: workflow_dispatch: + inputs: + environment: + description: 'Environment to deploy to' + required: true + default: 'production' + ref: + description: 'Git reference to deploy' + required: false jobs: build: From 959609181302fd204ca580dc80b7c4ac624562f6 Mon Sep 17 00:00:00 2001 From: david zhou Date: Mon, 17 Jun 2024 16:51:02 +1000 Subject: [PATCH 3/7] add a prod version for debugger --- debugger/Dockerfile.prod | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 debugger/Dockerfile.prod diff --git a/debugger/Dockerfile.prod b/debugger/Dockerfile.prod new file mode 100644 index 000000000..eca9ea4f8 --- /dev/null +++ b/debugger/Dockerfile.prod @@ -0,0 +1,25 @@ +# ===== Stage 1: Base Image with Python Installed ===== +FROM python:3.11-slim as base +ENV PYTHONUNBUFFERED=1 + +WORKDIR /app + +# Install dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# ===== Stage 2: Application Layer ===== +FROM base as final + +# Copy application code +COPY . . + +# Set a non-root user and switch to it +RUN useradd -m myuser +USER myuser + +# Set the port the app runs on +EXPOSE 8000 + +# Command to run your app +CMD ["python3", "-u", "src/server.py"] From 47c95f0bd37f4d027e4fa897ca4155b8fc02c5d3 Mon Sep 17 00:00:00 2001 From: david zhou Date: Mon, 17 Jun 2024 17:18:47 +1000 Subject: [PATCH 4/7] update secret --- .github/workflows/docker.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 43a5136a9..b24563248 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -54,6 +54,8 @@ jobs: needs: [build] concurrency: production environment: production + env: + VITE_DEBUGGER_URL: ${{ secrets.DEBUGGER_URL }} steps: - name: Checkout repository From e4407423c36cb70cb6a3810bd8feec297e2f7d18 Mon Sep 17 00:00:00 2001 From: david zhou Date: Mon, 17 Jun 2024 17:55:04 +1000 Subject: [PATCH 5/7] add environment variable in build --- .github/workflows/docker.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b24563248..7c31c0120 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -18,6 +18,8 @@ jobs: permissions: contents: read packages: write + env: + VITE_DEBUGGER_URL: ${{ secrets.DEBUGGER_URL }} strategy: fail-fast: false matrix: From 5cb822cfea65f17f7b5b04af26e6b3a2bee4466e Mon Sep 17 00:00:00 2001 From: david zhou Date: Thu, 27 Jun 2024 15:17:41 +1000 Subject: [PATCH 6/7] save prog on dev --- client/vite.config.ts | 2 +- debugger/Dockerfile.dev | 89 +++++++++++++++++++++++++---------------- deployment.sh | 3 ++ docker-compose.yml | 7 ++++ 4 files changed, 65 insertions(+), 36 deletions(-) create mode 100644 deployment.sh diff --git a/client/vite.config.ts b/client/vite.config.ts index 6f325cbb2..53a5a15c0 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -7,5 +7,5 @@ import checker from 'vite-plugin-checker'; export default defineConfig({ plugins: [react(), tsconfigPaths(), checker({ typescript: true })], build: { outDir: 'build' }, - server: { port: 3000 }, + server: { port: 3000, host: '0.0.0.0' }, }); diff --git a/debugger/Dockerfile.dev b/debugger/Dockerfile.dev index b9f0c35ad..ca156a02e 100644 --- a/debugger/Dockerfile.dev +++ b/debugger/Dockerfile.dev @@ -1,52 +1,71 @@ -FROM ubuntu +FROM ubuntu:latest -ENV DEBIAN_FRONTEND noninteractive +ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update -y; apt-get install -y build-essential gdb curl git libssl-dev zlib1g-dev \ - libbz2-dev libreadline-dev libsqlite3-dev \ - libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev +# Set up APT custom configurations +RUN echo "Acquire::http::Pipeline-Depth 0;" > /etc/apt/apt.conf.d/99custom && \ + echo "Acquire::http::No-Cache true;" >> /etc/apt/apt.conf.d/99custom && \ + echo "Acquire::BrokenProxy true;" >> /etc/apt/apt.conf.d/99custom -# Install python3 to run the backend server -RUN curl https://pyenv.run | bash +# Install dependencies +RUN apt-get update && apt-get upgrade -y --fix-missing \ + && apt-get install -y \ + build-essential \ + gdb \ + curl \ + git \ + libssl-dev \ + zlib1g-dev \ + libbz2-dev \ + libreadline-dev \ + libsqlite3-dev \ + libncursesw5-dev \ + xz-utils \ + tk-dev \ + libxml2-dev \ + libxmlsec1-dev \ + libffi-dev \ + liblzma-dev \ + python3 \ + python3-pip \ + python3-venv \ + python-is-python3 \ + && apt-get clean && \ + rm -rf /var/lib/apt/lists/* +# Setup pyenv and install Python ENV HOME="/root" -ENV PYENV_ROOT="${HOME}/.pyenv" -ENV PATH="${PYENV_ROOT}/bin:${PATH}" -# The following env var is needed to allow gdb to run our Python packages -# installed from requirements.txt -ENV PYTHONPATH="/root/.pyenv/versions/3.11.3/lib/python3.11/site-packages:${PYTHONPATH}" +ENV PYENV_ROOT="$HOME/.pyenv" +ENV PATH="$PYENV_ROOT/bin:$PATH" -ENV PYTHON_VERSION=3.11.3 - -# The following env var is needed to allow gdb to run our Python packages -# installed from requirements.txt -ENV PYTHONPATH="${PYENV_ROOT}/versions/${PYTHON_VERSION}/lib/python3.11/site-packages:${PYTHONPATH}" - -RUN pyenv install ${PYTHON_VERSION} -RUN pyenv global ${PYTHON_VERSION} +RUN curl https://pyenv.run | bash && \ + pyenv install 3.11.3 && \ + pyenv global 3.11.3 +# Install Python packages in a virtual environment COPY requirements.txt . -RUN pyenv exec pip3 install -r requirements.txt +RUN python3 -m venv /venv && \ + /venv/bin/pip install --upgrade pip && \ + /venv/bin/pip install -r requirements.txt +# Setup nvm and install Node.js ENV NODE_VERSION=20.0.0 -RUN apt install -y curl -RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash -ENV NVM_DIR=/root/.nvm -RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} -RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION} -RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION} -ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}" -RUN node --version -RUN npm --version +ENV NVM_DIR="$HOME/.nvm" +ENV PATH="$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH" + +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash && \ + . "$NVM_DIR/nvm.sh" && \ + nvm install $NODE_VERSION && \ + nvm use $NODE_VERSION && \ + nvm alias default $NODE_VERSION + +# Install global npm packages RUN npm install -g nodemon WORKDIR /app - COPY . . EXPOSE 8000 -# `python3 -u` option to prevent buffering output of print statements -# in the python server. Print to docker logs immediately. For easier -# debugging. -CMD [ "nodemon", "--exec", "pyenv", "exec", "python3", "-u", "src/server.py"] +# Command to run the application +CMD ["/venv/bin/python3", "-u", "src/server.py"] diff --git a/deployment.sh b/deployment.sh new file mode 100644 index 000000000..8784e47e5 --- /dev/null +++ b/deployment.sh @@ -0,0 +1,3 @@ +rsync -avz --exclude 'debugger/src/__pycache__' --exclude 'client/node_modules' --exclude '.git' --exclude '.env' \ +-e "ssh -i ~/.ssh/structs-deploy.pem" \ +. ubuntu@ec2-3-25-92-212.ap-southeast-2.compute.amazonaws.com:~/app diff --git a/docker-compose.yml b/docker-compose.yml index 4400c4b6a..db2cb7406 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,13 @@ services: - '8000:8000' volumes: - ./debugger/src:/app/src + environment: + - PYTHONPATH=/app + network_mode: "bridge" + logging: + options: + max-size: "10m" + max-file: "3" server: build: context: server From 54949550d8fa60b20b6e3a523cefcb594ee9bc65 Mon Sep 17 00:00:00 2001 From: david zhou Date: Fri, 28 Jun 2024 12:41:05 +1000 Subject: [PATCH 7/7] save --- deployment.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/deployment.sh b/deployment.sh index 8784e47e5..0f68e2259 100644 --- a/deployment.sh +++ b/deployment.sh @@ -1,3 +1,12 @@ +sudo curl -L "https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose +sudo chmod +x /usr/local/bin/docker-compose + + +sudo apt-get update +sudo apt-get install docker.io -y +sudo systemctl start docker + + rsync -avz --exclude 'debugger/src/__pycache__' --exclude 'client/node_modules' --exclude '.git' --exclude '.env' \ --e "ssh -i ~/.ssh/structs-deploy.pem" \ -. ubuntu@ec2-3-25-92-212.ap-southeast-2.compute.amazonaws.com:~/app +-e "ssh -i ~/.ssh/struct-deploy.pem" \ +. ubuntu@ec2-54-80-88-177.compute-1.amazonaws.com:~/app