Skip to content

first commit

first commit #1

name: Build and deploy a container to an Azure Web App
env:
AZURE_WEBAPP_NAME: peer-evaluation-tool
on:
push:
branches:
- main
permissions:
contents: "read"
packages: "write"
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Check out the repository
uses: actions/checkout@v4
# Step 2: Set up Node.js and build Vue.js (frontend)
- name: Set up Node.js 20
uses: actions/setup-node@v4
with:
node-version: "20"
# Step 3: Install dependencies and build Vue.js
- name: Install dependencies and build Vue.js
working-directory: ./frontend
run: |
npm install
npm run build-only
# Step 4: Copy the Vue build files to the Spring Boot static directory
# Even though static does exist in the Spring Boot project, it is not tracked by Git, so we need to create it.
- name: Copy Vue build files to Spring Boot static directory
run: |
mkdir -p ./backend/src/main/resources/static/
cp -r ./frontend/dist/* ./backend/src/main/resources/static/
# Step 5: Set up JDK 21 for building the Spring Boot project
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "temurin"
cache: "maven"
# Step 6: Build Spring Boot project with Maven (backend)
- name: Build with Maven
working-directory: ./backend
run: mvn --batch-mode --update-snapshots package -DskipTests
# Step 7: Set up Docker Buildx for containerization
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Step 8: Log in to GitHub container registry
- name: Log in to GitHub container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Step 9: Lowercase the repo name for consistency
- name: Lowercase the repo name
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
# Step 10: Build and push container image to registry
- name: Build and push container image to registry
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/${{ env.REPO }}:${{ github.sha }}
file: ./Dockerfile
deploy:
runs-on: ubuntu-latest
needs: build
steps:
# Step 11: Lowercase the repo name
- name: Lowercase the repo name
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
# Step 12: Deploy to Azure Web App using publish profile
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
images: "ghcr.io/${{ env.REPO }}:${{ github.sha }}"