feat(front) Different dockerfiles iso prod/dev + Create reading list … #19
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: Web CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- frontend/** | |
jobs: | |
lint-and-test: | |
name: Lint and Test Code | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- name: Cache Node.js modules | |
uses: actions/cache@v4 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install Dependencies | |
working-directory: ./frontend | |
run: npm install | |
- name: Run Prettier Check | |
working-directory: ./frontend | |
run: npx prettier --check . | |
- name: Run ESLint | |
working-directory: ./frontend | |
run: npx eslint . | |
- name: Install Playwright Browsers | |
working-directory: ./frontend | |
run: npx playwright install --with-deps | |
- name: Run Tests | |
working-directory: ./frontend | |
run: npx playwright test | |
build: | |
name: Build Application | |
runs-on: ubuntu-latest | |
needs: lint-and-test | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- name: Cache Node.js modules | |
uses: actions/cache@v4 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install Dependencies | |
working-directory: ./frontend | |
run: npm ci | |
- name: Build the App | |
working-directory: ./frontend | |
run: npm run build | |
- name: Upload Build Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: frontend-build | |
path: ./frontend/build | |
docker: | |
name: Build and Push Docker Image | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Download Build Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: frontend-build | |
path: ./frontend/build | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build Docker Image | |
working-directory: ./frontend | |
run: | | |
docker build -f prod.Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/portfolio:frontend-latest . | |
docker tag ${{ secrets.DOCKER_USERNAME }}/portfolio:frontend-latest ${{ secrets.DOCKER_USERNAME }}/portfolio:frontend-${{ github.sha }} | |
- name: Push Docker Image | |
run: | | |
docker push ${{ secrets.DOCKER_USERNAME }}/portfolio:frontend-latest | |
docker push ${{ secrets.DOCKER_USERNAME }}/portfolio:frontend-${{ github.sha }} | |
deploy: | |
name: Deploy to k3s | |
runs-on: ubuntu-latest | |
needs: docker | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set up kubectl | |
uses: azure/setup-kubectl@v4 | |
with: | |
version: "latest" | |
- name: Configure kubeconfig | |
run: | | |
mkdir -p $HOME/.kube | |
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config | |
- name: Apply Kubernetes Manifest | |
run: | | |
kubectl apply -f k8s/front/frontend-deployment.yaml | |
- name: Wait for Rollout | |
run: | | |
kubectl rollout status deployment/frontend |