-
Notifications
You must be signed in to change notification settings - Fork 3
Implement CI/CD Pipeline with Production Environment (Fixes #4) #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bbdf9cc
02eeb4f
77ee783
0cf4c55
4ea570c
2c23b73
d1972e4
131a786
7fddcfe
1beae1e
5257325
730937c
81afc43
5b0fea5
31a12a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| .Python | ||
| [Bb]in | ||
| [Ii]nclude | ||
| [Ll]ib | ||
| [Ll]ib64 | ||
| [Ll]ocal | ||
| [Ss]cripts | ||
| pyvenv.cfg | ||
| .venv | ||
| pip-selfcheck.json | ||
| .idea | ||
| *.iml | ||
| out | ||
| gen | ||
| *.zwc | ||
| *.zwc.old | ||
| *zcompdump* | ||
| .zsh_history | ||
| .zsh_sessions | ||
| .zcalc_history | ||
| ._zinit | ||
| .zinit_lstupd | ||
| zsdoc/data | ||
| .directory_history | ||
| /tests/_output/* | ||
| !/tests/_output/.gitkeep | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
| *.so | ||
| build/ | ||
| develop-eggs/ | ||
| dist/ | ||
| downloads/ | ||
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
| var/ | ||
| wheels/ | ||
| share/python-wheels/ | ||
| *.egg-info/ | ||
| .installed.cfg | ||
| *.egg | ||
| MANIFEST | ||
| *.manifest | ||
| *.spec | ||
| pip-log.txt | ||
| pip-delete-this-directory.txt | ||
| htmlcov/ | ||
| .tox/ | ||
| .nox/ | ||
| .coverage | ||
| .coverage.* | ||
| .cache | ||
| nosetests.xml | ||
| coverage.xml | ||
| *.cover | ||
| *.py,cover | ||
| .hypothesis/ | ||
| .pytest_cache/ | ||
| cover/ | ||
| *.mo | ||
| *.pot | ||
| *.log | ||
| local_settings.py | ||
| db.sqlite3 | ||
| db.sqlite3-journal | ||
| instance/ | ||
| .webassets-cache | ||
| .scrapy | ||
| docs/_build/ | ||
| .pybuilder/ | ||
| target/ | ||
| .ipynb_checkpoints | ||
| profile_default/ | ||
| ipython_config.py | ||
| .pdm.toml | ||
| __pypackages__/ | ||
| celerybeat-schedule | ||
| celerybeat.pid | ||
| *.sage.py | ||
| .env | ||
| env/ | ||
| venv/ | ||
| ENV/ | ||
| env.bak/ | ||
| venv.bak/ | ||
| .spyderproject | ||
| .spyproject | ||
| .ropeproject | ||
| /site | ||
| .mypy_cache/ | ||
| .dmypy.json | ||
| dmypy.json | ||
| .pyre/ | ||
| .pytype/ | ||
| cython_debug/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Bot Configuration | ||
| BOT_TOKEN=your_telegram_bot_token_here | ||
| DATABASE_NAME=playlist.db | ||
| ADD_TRACK_TIME_WINDOW=60 | ||
| LOG_LEVEL=INFO | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also we need |
||
|
|
||
| # GitHub Actions Secrets (set these in repository settings > Secrets and variables > Actions) | ||
| # DOCKER_USERNAME=your_docker_hub_username | ||
| # DOCKER_PASSWORD=your_docker_hub_password_or_token | ||
| # SERVER_HOST=your_server_ip_or_hostname | ||
| # SERVER_USER=your_server_ssh_username | ||
| # SERVER_SSH_KEY=your_private_ssh_key_content | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,102 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: CI/CD Pipeline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| push: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| branches: [ main ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tags: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - "v*.*.*" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pull_request: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| branches: [ main ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| build: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| environment: prod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Checkout code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Set up Docker Buildx | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: docker/setup-buildx-action@v3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Build Docker image | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| docker buildx build --platform linux/amd64 -t bilbomusicbot:latest --load . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Test Docker image | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| docker run --rm -e BOT_TOKEN=${{ secrets.BOT_TOKEN }} bilbomusicbot:latest python -c " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import bot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print('Bot module imported successfully') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f'Import failed: {e}') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
anvaari marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| release: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| needs: build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| environment: prod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if: startsWith(github.ref, 'refs/tags/v') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Checkout code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Set up Docker Buildx | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: docker/setup-buildx-action@v3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Login to Docker Hub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: docker/login-action@v3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| username: ${{ secrets.DOCKER_USERNAME }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # if your server support ssh key use this format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # key: ${{ secrets.SERVER_SSH_KEY }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Build and push Docker image | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| docker buildx build --platform linux/amd64,linux/arm64 \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -t ${{ secrets.DOCKER_USERNAME }}/bilbomusicbot:latest \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -t ${{ secrets.DOCKER_USERNAME }}/bilbomusicbot:${{ github.ref_name }} \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --push . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Copy docker-compose.yml to server | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: appleboy/scp-action@v0.1.7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| host: ${{ secrets.SERVER_HOST }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| username: ${{ secrets.SERVER_USER }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| password: ${{ secrets.SERVER_SSH_KEY }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source: "docker-compose.yml" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target: "/opt/bilbomusicbot/" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+64
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect credential field for SCP: use You’re passing an SSH private key via the Apply: - - name: Copy docker-compose.yml to server
- uses: appleboy/scp-action@v0.1.7
- with:
- host: ${{ secrets.SERVER_HOST }}
- username: ${{ secrets.SERVER_USER }}
- password: ${{ secrets.SERVER_SSH_KEY }}
- source: "docker-compose.yml"
- target: "/opt/bilbomusicbot/"
+ - name: Prepare server for deployment
+ uses: appleboy/ssh-action@v1.0.3
+ with:
+ host: ${{ secrets.SERVER_HOST }}
+ username: ${{ secrets.SERVER_USER }}
+ key: ${{ secrets.SERVER_SSH_KEY }}
+ script: |
+ mkdir -p /opt/bilbomusicbot
+ docker pull ${{ secrets.DOCKER_USERNAME }}/bilbomusicbot:latest
+
+ - name: Copy docker-compose.yml to server
+ uses: appleboy/scp-action@v0.1.7
+ with:
+ host: ${{ secrets.SERVER_HOST }}
+ username: ${{ secrets.SERVER_USER }}
+ key: ${{ secrets.SERVER_SSH_KEY }}
+ source: "docker-compose.yml"
+ target: "/opt/bilbomusicbot/"Note: This reorders steps so the directory exists before SCP and fixes the credential field. 📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 72-72: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Art4Man please use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Prepare server for deployment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: appleboy/ssh-action@v1.0.3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| host: ${{ secrets.SERVER_HOST }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| username: ${{ secrets.SERVER_USER }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| password: ${{ secrets.SERVER_SSH_KEY }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| script: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p /opt/bilbomusicbot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cd /opt/bilbomusicbot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| docker pull ${{ secrets.DOCKER_USERNAME }}/bilbomusicbot:latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
anvaari marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deploy: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| needs: release | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| environment: prod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if: startsWith(github.ref, 'refs/tags/v') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Deploy to server | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: appleboy/ssh-action@v1.0.3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| host: ${{ secrets.SERVER_HOST }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| username: ${{ secrets.SERVER_USER }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| password: ${{ secrets.SERVER_SSH_KEY }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| script: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
anvaari marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cd /opt/bilbomusicbot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export BOT_TOKEN=${{ secrets.BOT_TOKEN }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| docker compose down | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| docker compose up -d | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| docker system prune -f | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,11 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM python:3.13-slim | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WORKDIR /app | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY requirements.txt . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN pip install --no-cache-dir -r requirements.txt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY . . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CMD ["python", "bot.py"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+11
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Run as non-root and add Python runtime envs Running as root is risky in production. Also consider standard Python envs to reduce noise and improve logging behavior. FROM python:3.13-slim
WORKDIR /app
+ENV PYTHONDONTWRITEBYTECODE=1 \
+ PYTHONUNBUFFERED=1
+
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
-CMD ["python", "bot.py"]
+# Create non-root user and switch
+RUN addgroup --system app && adduser --system --ingroup app app && \
+ chown -R app:app /app
+USER app
+
+CMD ["python", "bot.py"]📝 Committable suggestion
Suggested change
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Art4Man Also please consider this suggestion.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks a lot for this great PR @Art4Man . |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| services: | ||
| bilbomusicbot: | ||
| image: ${DOCKER_USERNAME}/bilbomusicbot:latest | ||
| container_name: bilbomusicbot | ||
| restart: unless-stopped | ||
| environment: | ||
| - BOT_TOKEN=${BOT_TOKEN} | ||
| volumes: | ||
| - ./data:/app/data | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't data folder. It's better to mount |
||
| networks: | ||
| - bilbonet | ||
|
|
||
| networks: | ||
| bilbonet: | ||
| driver: bridge | ||
|
|
||
| volumes: | ||
| data: | ||
Uh oh!
There was an error while loading. Please reload this page.