Skip to content

fix: CI

fix: CI #5

Workflow file for this run

name: CI/CD to staging
on:
push:
branches:
- main
jobs:
CI:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Build and test code
run: |
cargo build --verbose
cargo test --verbose
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker images
uses: docker/[email protected]
with:
push: true
files: docker-compose.yml
set: |
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
CD:
needs: CI
runs-on:
- self-hosted
- staging
steps:
- name: Checkout the latest code
uses: actions/checkout@v3
- name: Docker Hub login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Remove specific old containers if they exist
run: |
docker stop rest-api-staging || true
docker rm rest-api-staging || true
- name: Pull the Docker images
run: |
cd $GITHUB_WORKSPACE
docker compose -f docker-compose.yml pull rest-api
- name: Start the containers
run: |
cd $GITHUB_WORKSPACE
docker compose -f docker-compose.yml up -d rest-api
- name: Remove old Docker images
run: |
docker rmi $(docker images -f "dangling=true" -q) || true
# docker rmi $(docker images devroadr/python-api-server -f "dangling=true" -q) || true