Skip to content

Commit

Permalink
Continuous deployment ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomansion committed Apr 7, 2024
1 parent dc4a8b2 commit 3d42170
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/continuous-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Continuous Deployment

on:
push:
branches:
- main

# Declare variables
env:
APP_NAME: web_app_template

jobs:
build:
name: Build the docker image
runs-on: ubuntu-20.04

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to docker hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build the Docker image
run: docker build . -t ${{ env.APP_NAME }}

- name: Tag the Docker image with latest and the tag name
run: |
echo ${{ github.sha }}
docker tag ${{ env.APP_NAME }} ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}:latest
- name: Upload Docker image to Docker Hub
run: docker push ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }} --all-tags

deploy:
needs: build
name: Deploy to hosted server
runs-on: ubuntu-20.04
steps:
- name: Remote ssh
uses: appleboy/ssh-action@master
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
password: ${{secrets.SSH_PASSWORD}}
port: ${{secrets.SSH_PORT}}
script: ${{secrets.SSH_PASSWORD}}
61 changes: 55 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,46 @@ docker-compose up --build

The application should be available at: [http://localhost:3000](http://localhost:3000)

### Setting up the GitHub continuous deployment pipeline

This project includes a GitHub Actions workflow that builds the Docker image, pushes it to the Docker Hub image registry, and deploys the application by calling an SSH script.

#### Prerequisites

- A Linux server with Docker and Docker Compose installed.
- A [Docker Hub](https://hub.docker.com/) account.

#### Steps

1. Create a new repository from this template and push it to GitHub.
2. Copy and edit the [`docker-compose.yml`](docker-compose.yml) file to your server.
- Edit the images to point to your Docker Hub repository.
- Edit the environment variables to match your configuration.
- Edit the container names and the other configurations as needed.
- Add your Nginx or Traefik configuration if needed.
3. Create, on your server a `deploy.sh` script with the following content:

```bash
# deploy.sh
cd /path/to/your/application
docker-compose pull
docker-compose up -d
# Use chmod +x deploy.sh to make the script executable
```

4. Add the following secrets to your repository:
- `DOCKER_USERNAME`: Your Docker Hub username.
- `DOCKER_PASSWORD`: Your Docker Hub password.
- `SSH_HOST`: The IP address of the server where you want to deploy the application.
- `SSH_PORT`: The port to connect to the server.
- `SSH_USERNAME`: The username to connect to the server.
- `SSH_PASSWORD`: The user password to connect to the server.
- `SSH_SCRIPT_PATH`: The absolute path to the `deploy.sh` script on the server.
5. Modify the `APP_NAME`in the [continuous-deployment.yml](./.github/workflows/continuous-deployment.yml) file to match your application name.
6. Push the changes to your repository.

The GitHub Actions workflow will run when you push the changes to the repository `main` branch. It will build the Docker image, push it to the Docker Hub image registry, and deploy the application by calling the `deploy.sh` script on your server.

### Recommended VSCode extensions

- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
Expand All @@ -161,14 +201,23 @@ The application should be available at: [http://localhost:3000](http://localhost
- [flake8](https://marketplace.visualstudio.com/items?itemName=ms-python.flake8)
- [cSpell](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker)

## Help

If you have any questions or need help, feel free to [open an issue](https://github.com/Tomansion/Vue3-FastAPI-WebApp-template/issues).

## Contributing

I'm open to contributions and suggestions. Feel free to [open an issue](https://github.com/Tomansion/Vue3-FastAPI-WebApp-template/issues) or a make a pull request.

## TODO

- [ ] Add i18n
- [ ] Add demo link
- [ ] Add custom styles
- [ ] Add authentication
- [ ] Add CI/CD pipeline
- [ ] Add frontend tests
- [ ] CI/CD pipeline
- [ ] Demo link
- [ ] Custom styles
- [ ] I18n
- [ ] Authentication
- [ ] Frontend tests
- [ ] Frontend to mobile app
- [x] Pinia store
- [x] Arango Database
- [x] Backend tests and coverage
1 change: 0 additions & 1 deletion backend/utils/database_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def get_notes() -> List[dict]:

@db_must_be_setup
def get_note(note_id) -> Optional[dict]:
print(f" - Getting note {colored(note_id, DEBUG_COLOR)}")
note = db.collection(NOTES_COLLECTION_NAME).get(note_id)
if note is not None:
note["id"] = note["_key"]
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"socketio",
"termcolor",
"tomansion",
"Traefik",
"unplugin",
"uvicorn",
"Vetur",
Expand Down
3 changes: 3 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ run_frontend:
run:
make run_backend & make run_frontend

start:
make runk

# Testing
install_test:
pip install coverage pytest pytest-cov
Expand Down

0 comments on commit 3d42170

Please sign in to comment.