Skip to content

Commit

Permalink
Setup github actions for CI/CD pipeline with build testing, deploy to…
Browse files Browse the repository at this point in the history
… production server and docker image
  • Loading branch information
dotpep committed Feb 29, 2024
1 parent 2d36508 commit bf1528b
Showing 1 changed file with 36 additions and 57 deletions.
93 changes: 36 additions & 57 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
steps:
- name: Checkout Pulling Git Repo
uses: actions/checkout@v4

- name: Install Python version 3.10
uses: actions/setup-python@v5
with:
Expand All @@ -44,30 +43,11 @@ jobs:
# run: python -m pip install --upgrade pip
#- name: Install dependencies
# run: pip install -r requirements.txt

#- name: Run tests with PyTest
# run: |
# pip install pytest
# pytest -v

#- name: Install Poetry version 1.7.1
# uses: abatilo/actions-poetry@v2
# with:
# poetry-version: '1.7.1'
#- name: Setup a local virtual environment (if no poetry.toml file)
# run: |
# poetry config virtualenvs.create true --local
# poetry config virtualenvs.in-project true --local
#- uses: actions/cache@v3
# name: Define a cache for the virtual environment based on the dependencies lock file
# with:
# path: ./.venv
# key: venv-${{ hashFiles('poetry.lock') }}
#- name: Install the project dependencies
# run: poetry install
#- name: Run the automated tests with PyTest
# run: poetry run pytest -v

- name: Install Poetry
uses: snok/install-poetry@v1
with:
Expand All @@ -81,7 +61,6 @@ jobs:
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install project dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
Expand Down Expand Up @@ -125,46 +104,46 @@ jobs:
password: ${{ secrets.PROD_PASSWORD }}
script: |
cd api/src
git pull
poetry install --no-interaction
git pull origin main
poetry install --no-interaction --no-root
poetry run alembic upgrade head
echo ${{ secrets.PROD_PASSWORD }} | sudo -S systemctl restart api
# login to our vps ubuntu server with ssh
# cd api/src
# git pull
# systemctl restart api

#docker:
# runs-on: ubuntu-20.04
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# - name: Cache Docker layers
# uses: actions/cache@v3
# with:
# path: /tmp/.buildx-cache
# key: ${{ runner.os }}-buildx-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-buildx-
# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# - name: Build and push
# uses: docker/build-push-action@v5
# with:
# context: .
# push: true
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/social-media-fastapi:latest
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
# - # Temp fix
# # https://github.com/docker/build-push-action/issues/252
# # https://github.com/moby/buildkit/issues/1896
# name: Move cache
# run: |
# rm -rf /tmp/.buildx-cache
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache
docker:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/social-media-fastapi:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- # Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

0 comments on commit bf1528b

Please sign in to comment.