Trigger auto deployment #4
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: Trigger auto deployment | |
on: | |
# 手動実行用トリガー | |
workflow_dispatch: | |
env: | |
CONTAINER_REGISTRY: cicd2024rymvmpzpk74hg.azurecr.io | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout to the branch | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Set repository name to env | |
run: | | |
echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" >> $GITHUB_ENV | |
- name: Confirm if env have REPOSITORY_NAME | |
run: | | |
echo ${{ env.REPOSITORY_NAME }} | |
# Add a step | |
- name: Log in to container registry | |
# 認証処理を行うためのアクション | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.CONTAINER_REGISTRY }} | |
username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }} | |
password: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }} | |
# Add a step | |
- name: Build and push container image to registry | |
uses: docker/build-push-action@v3 | |
with: | |
push: true | |
tags: ${{ env.CONTAINER_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ github.sha }} | |
file: ./Dockerfile | |
context: ./ | |
# Add a job and steps | |
deploy: | |
runs-on: ubuntu-22.04 | |
needs: build | |
# Add a id-token permission | |
permissions: | |
id-token: write | |
steps: | |
- name: Set repository name to env | |
run: | | |
echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" >> $GITHUB_ENV | |
- name: Confirm if env have REPOSITORY_NAME | |
run: | | |
echo ${{ env.REPOSITORY_NAME }} | |
# Add a step | |
- name: Azure Login using OIDC | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |