setup & install flake8 manually in ci #77
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
name: CI | |
on: | |
push: | |
branches: | |
- 'main' | |
pull_request: | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
lint-frontend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup nodejs | |
uses: actions/setup-node@v4 | |
- name: Install dependencies | |
working-directory: ./frontend | |
run: npm install | |
- name: Run linter | |
working-directory: ./frontend | |
run: npm run lint | |
lint-core: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup python | |
uses: actions/setup-python@v5 | |
with: | |
cache: 'pip' | |
- name: Install dependencies | |
run: | | |
python -m venv venv | |
source venv/bin/activate | |
pip install --upgrade pip | |
pip install flake8 | |
- name: Run flake8 | |
run: | | |
source venv/bin/activate | |
flake8 --exclude=core/alembic/versions/ core | |
build: | |
name: Build docker image | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- context: frontend | |
image: scystream-frontend | |
- context: core | |
image: scystream-core | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.image }} | |
tags: | | |
type=ref,event=pr | |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} | |
- name: Define build args | |
id: define_build_args | |
run: | | |
if [ "${{ matrix.context }}" == "frontend" ]; then | |
echo "BUILD_ARGS=NEXT_PUBLIC_API_URL=${{ secrets.BUILD_API_URL }}" >> $GITHUB_ENV | |
else | |
echo "BUILD_ARGS=" >> $GITHUB_ENV | |
fi | |
- name: Build and push docker images | |
uses: docker/build-push-action@v5 | |
with: | |
context: ${{ matrix.context }} | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: ${{ env.BUILD_ARGS }} | |
deploy: | |
name: Deploy Docker containers | |
runs-on: self-hosted | |
needs: build | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Write SSH keys | |
run: | | |
install -m 600 -D /dev/null ~/id_rsa | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/id_rsa | |
- name: SSH Deploy | |
run: | | |
ssh -i ~/id_rsa -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOSTNAME }} << 'EOF' | |
docker pull ${{ env.REGISTRY }}/rwth-time/scystream/scystream-frontend:latest | |
docker pull ${{ env.REGISTRY }}/rwth-time/scystream/scystream-core:latest | |
docker compose down && docker compose up -d | |
EOF |