Lint, Build and Push Docker Images #136
Workflow file for this run
This file contains hidden or 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: Lint, Build and Push Docker Images | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ["v*"] | |
| pull_request: | |
| branches: [main] | |
| create: | |
| tags: ["v*"] | |
| env: | |
| REGISTRY: ghcr.io | |
| FRONTEND_IMAGE_NAME: ${{ github.repository }}/frontend | |
| BACKEND_IMAGE_NAME: ${{ github.repository }}/backend | |
| jobs: | |
| lint: | |
| name: Run Linters | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install and cache Python dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r api/requirements.txt -r api/requirements-dev.txt | |
| - name: Run backend linters | |
| run: | | |
| cd api | |
| black --check --diff . | |
| isort --check-only --diff . | |
| flake8 . | |
| mypy . | |
| - name: Set up Node.js and pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| # - name: Setup Node.js | |
| # uses: actions/setup-node@v4 | |
| # with: | |
| # node-version: "18" | |
| # cache: "pnpm" | |
| - name: Install frontend dependencies | |
| run: cd ui && pnpm install | |
| - name: Run frontend linter | |
| run: cd ui && pnpm lint | |
| build-and-push: | |
| name: Build and Push Docker Images | |
| needs: lint | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # - name: Cache Frontend Dependencies | |
| # uses: actions/cache@v4 | |
| # with: | |
| # path: | | |
| # ui/node_modules | |
| # ~/.pnpm-store | |
| # key: ${{ runner.os }}-frontend-deps-${{ hashFiles('ui/package.json') }}-${{ hashFiles('ui/pnpm-lock.yaml') }} | |
| # restore-keys: | | |
| # ${{ runner.os }}-frontend-deps-${{ hashFiles('ui/package.json') }} | |
| # ${{ runner.os }}-frontend-deps- | |
| - name: Cache Backend Dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/pip | |
| key: ${{ runner.os }}-backend-deps-${{ hashFiles('api/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-backend-deps- | |
| - name: Extract metadata for frontend | |
| id: meta-frontend | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Extract metadata for backend | |
| id: meta-backend | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Build and push frontend image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./docker/ui.Dockerfile | |
| push: ${{ startsWith(github.ref, 'refs/tags/') }} | |
| tags: ${{ steps.meta-frontend.outputs.tags }} | |
| labels: ${{ steps.meta-frontend.outputs.labels }} | |
| build-args: | | |
| NUXT_PUBLIC_VERSION=${{ steps.meta-frontend.outputs.version }} | |
| cache-from: type=gha,scope=frontend | |
| cache-to: type=gha,mode=max,scope=frontend | |
| platforms: linux/amd64 | |
| - name: Build and push backend image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./docker/api.Dockerfile | |
| push: ${{ startsWith(github.ref, 'refs/tags/') }} | |
| tags: ${{ steps.meta-backend.outputs.tags }} | |
| labels: ${{ steps.meta-backend.outputs.labels }} | |
| cache-from: type=gha,scope=backend | |
| cache-to: type=gha,mode=max,scope=backend | |
| platforms: linux/amd64 |