Create GitHub Actions #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: Docker Build and Push | |
on: | |
push: | |
branches: | |
- main # 例: mainブランチにpushされたら実行 | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
# 1) ソースコードをチェックアウト | |
- name: Check out code | |
uses: actions/checkout@v3 | |
# 2) GHCR へのログイン (docker/login-action) | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
# デフォルトの GITHUB_TOKEN を利用 (Write 権限が必要) | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# 3) Docker イメージをビルド&プッシュ (docker/build-push-action) | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v3 | |
with: | |
# コンテキスト(Dockerfile がある場所) | |
context: . | |
# 今回はプッシュまで行うので true | |
push: true | |
# タグを指定 (例: ghcr.io/{リポジトリ名}/アプリ名:タグ) | |
tags: ghcr.io/${{ github.repository }}/todo-app:latest |