This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
chore: workflows #8
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/CD using GitHub Actions & Bicep | |
on: | |
push: | |
branches: [ "master" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | |
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }} | |
AZURE_LOCATION: ${{ secrets.AZURE_LOCATION }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Set yml file | |
uses: microsoft/variable-substitution@v1 | |
with: | |
files: src/main/resources/application.yml | |
env: | |
spring.datasource.url: ${{ secrets.DB_URL }} | |
spring.datasource.username: ${{ secrets.DB_USERNAME }} | |
spring.datasource.password: ${{ secrets.DB_PASSWORD }} | |
app.jwt.secretKey: ${{ secrets.TOKEN_SECRET_KEY }} | |
app.jwt.accessExpire: ${{ secrets.ACCESS_EXPIRE }} | |
app.jwt.refreshExpire: ${{ secrets.REFRESH_EXPIRE }} | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew build | |
- name: List build/libs contents | |
run: ls -la build/libs | |
- name: Docker build | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/sodam . | |
docker push ${{ secrets.DOCKER_USERNAME }}/sodam:latest | |
- name: Install azd | |
uses: Azure/[email protected] | |
- name: Log in with Azure using Service Principal | |
run: | | |
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }} | |
shell: bash | |
- name: Install Bicep CLI | |
run: az bicep install | |
- name: Validate Bicep file | |
run: az bicep build --file ./main.bicep | |
- name: Deploy Azure Infrastructure using Bicep | |
run: | | |
az deployment group create \ | |
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ | |
--template-file ./main.bicep \ | |
--parameters @./parameters.json | |
- name: Configure Azure App Service to use Docker container | |
run: | | |
az webapp config container set \ | |
--name ${{ secrets.AZURE_APP_NAME }} \ | |
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ | |
--docker-custom-image-name ${{ secrets.DOCKER_USERNAME }}/sodam:latest \ | |
--docker-registry-server-url https://index.docker.io \ | |
--docker-registry-server-user ${{ secrets.DOCKER_USERNAME }} \ | |
--docker-registry-server-password ${{ secrets.DOCKER_PASSWORD }} | |
- name: Restart Azure App Service | |
run: | | |
az webapp restart --name ${{ secrets.AZURE_APP_NAME }} --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} |