-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from hrspace-request-builder/feature/ci_cd
Feature/ci cd
- Loading branch information
Showing
4 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
name: Test Suite | ||
|
||
name: CI/CD | ||
on: | ||
push: | ||
branches: ["main", "develop"] | ||
branches: ["develop"] | ||
pull_request: | ||
branches: ["main", "develop"] | ||
branches: ["develop"] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
|
@@ -29,3 +28,81 @@ jobs: | |
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements/test.requirements.txt | ||
build_and_push_to_docker_hub: | ||
name: Push Docker image to Docker Hub | ||
runs-on: ubuntu-latest | ||
needs: tests | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v4 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to Docker | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
- name: Push to Docker Hub | ||
uses: docker/build-push-action@v4 | ||
with: | ||
file: ./docker/dev.Dockerfile | ||
push: true | ||
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}:latest | ||
|
||
server_environment: | ||
runs-on: ubuntu-latest | ||
needs: build_and_push_to_docker_hub | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v4 | ||
- name: Create project directory and .env-file | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
script: | | ||
sudo mkdir -p ${{ secrets.PROJECT_NAME }} | ||
sudo chmod 777 ${{ secrets.PROJECT_NAME }} | ||
sudo cat > ${{ secrets.PROJECT_NAME }}/.env << _EOF_ | ||
APP_TITLE=${{ secrets.APP_TITLE }} | ||
APP_DESCRIPTION=${{ secrets.APP_DESCRIPTION }} | ||
SECRET_KEY=${{ secrets.SECRET_KEY }} | ||
POSTGRES_USER=${{ secrets.POSTGRES_USER }} | ||
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} | ||
DB_HOST=${{ secrets.DB_HOST }} | ||
DB_PORT=${{ secrets.DB_PORT }} | ||
POSTGRES_DB=${{ secrets.POSTGRES_DB }} | ||
PROJECT_NAME=${{ secrets.PROJECT_NAME }} | ||
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }} | ||
_EOF_ | ||
- name: copy infra files via ssh | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
source: "docker/server.docker-compose.yml" | ||
target: ${{ secrets.PROJECT_NAME }} | ||
overwrite: true | ||
strip_components: 1 | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: server_environment | ||
steps: | ||
- name: Deploy | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
script: | | ||
cd ${{ secrets.PROJECT_NAME }} | ||
sudo docker-compose -f server.docker-compose.yml --env-file .env down | ||
sudo docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} | ||
sudo systemctl stop nginx | ||
sudo docker-compose -f server.docker-compose.yml --env-file .env up -d --quiet-pull |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,7 @@ ipython_config.py | |
fastapi.db | ||
test.db | ||
_main.yml | ||
_server* | ||
_test* | ||
=GARB= | ||
infra/local/admin | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
version: '3' | ||
services: | ||
|
||
db: | ||
image: postgres:15.1-alpine | ||
restart: always | ||
volumes: | ||
- db_data:/var/lib/postgresql/data/ | ||
environment: | ||
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD | ||
ports: | ||
- $DB_PORT:$DB_PORT | ||
|
||
backend: | ||
image: "${DOCKERHUB_USERNAME}/${PROJECT_NAME}" | ||
# command: bash -c "alembic upgrade head && uvicorn app.main:app" | ||
command: bash -c "uvicorn app.main:app --host=0.0.0.0" | ||
restart: always | ||
depends_on: | ||
- db | ||
ports: | ||
- 8000:8000 | ||
env_file: | ||
- ./.env | ||
|
||
volumes: | ||
db_data: |