Merge pull request #7 from HwiYul-G/07-CICD #1
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: Build and deploy a container to an Azure Web App | |
env: | |
AZURE_WEBAPP_NAME: java-board | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: 'read' | |
packages: 'write' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: 'maven' | |
- name: Build with Maven | |
run: mvn --batch-mode --update-snapshots package -DskipTests | |
- 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: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Lowercase the repo name | |
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} | |
- name: Build and push container image to registry | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ghcr.io/${{ env.REPO }}:${{ github.sha }} | |
file: ./Dockerfile | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Lowercase the repo name | |
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} | |
- 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 }}' |