Skip to content

Commit

Permalink
ci(ts): add automation test
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 28, 2024
1 parent 7bfcc5e commit 20381e7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
26 changes: 13 additions & 13 deletions template/ts/{{cookiecutter.project_slug}}/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ on:
{% raw %}
jobs:
build-and-test:
name: python-${{ matrix.os }}
name: Node.js-${{ matrix.node }}

strategy:
matrix:
node: [ 18, 20, 22 ]
os:
- ubuntu-latest
- windows-latest
Expand All @@ -26,18 +27,17 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up uv
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }}
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Set up uv
if: ${{ matrix.os == 'windows-latest' }}
run: irm https://astral.sh/uv/install.ps1 | iex
shell: powershell
- name: Init dependencies
run: make init

- name: Build & Test
run: |
make init
make build
make test
- name: Build
run: make build

- name: Run tests
run: make test
{% endraw %}
53 changes: 27 additions & 26 deletions template/ts/{{cookiecutter.project_slug}}/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
# Base image for building the virtual environment
FROM python:{{cookiecutter.python_version}}-bookworm AS builder
# Base image for building the application
FROM node:{{cookiecutter.node_version}}-bookworm AS builder

ENV PATH="/root/.cargo/bin:$PATH" \
UV_INDEX_URL="https://mirrors.cernet.edu.cn/pypi/web/simple" \
PIP_INDEX_URL="https://mirrors.cernet.edu.cn/pypi/web/simple"
# Set working directory
WORKDIR /app

# Install uv and tools
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
# Copy package.json and package-lock.json to the container
COPY package.json yarn.lock ./

WORKDIR /app
# Install dependencies
RUN yarn install

COPY pyproject.toml .
# Copy the rest of the application code
COPY . .

# Create and install dependencies in the virtual environment
RUN uv sync
# Build the application
RUN yarn build

# Separate stage for validation (build and test)
FROM builder AS validator

WORKDIR /app
COPY . .

# Run build and test as part of the validation
RUN make build && make test
# Run tests as part of the validation
RUN yarn test

# Final image for running the application
FROM python:{{cookiecutter.python_version}}-slim-bookworm
FROM node:{{cookiecutter.node_version}}-slim-bookworm

LABEL author="{{cookiecutter.full_name}}"

ENV PATH="/app/.venv/bin:$PATH" \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

# Set working directory
WORKDIR /app

# Copy the virtual environment and application code
COPY --from=builder /app/.venv /app/.venv
COPY src ./src
# Copy built application code and node_modules from builder
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY package.json yarn.lock ./

# Expose the port the app runs on
EXPOSE 3000

HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"
# Define a health check
HEALTHCHECK --start-period=30s CMD curl -f http://localhost:3000 || exit 1

CMD ["python", "src/{{cookiecutter.package_name}}/app.py"]
# Start the application
CMD ["node", "dist/index.js"]

0 comments on commit 20381e7

Please sign in to comment.