-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3b08d1
commit 13aef12
Showing
10 changed files
with
116 additions
and
33 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Dockerでビルドしたpackageをgithub-pagesにホストする | ||
on: | ||
push: | ||
# branches: | ||
# - master | ||
|
||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
# env: | ||
# GITHUB_CONTAINER_REGISTRY_TAG: ryosukedtomita/github-pages-test-docker | ||
# IMAGE_NAME: react-app | ||
|
||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
|
||
# dockerでbuildしたパッケージをローカルにコピーする。 | ||
- name: Build app with docker | ||
run: | | ||
docker buildx bake --set react-app.args.BUILD_ENV=staging | ||
docker compose cp react-app:/usr/share/nginx/html build | ||
# Deploymentsにupload | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1 | ||
with: | ||
path: ./build | ||
|
||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
needs: build | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# GitHub-pagesを使う | ||
|
||
## package.jsonに設定追加 | ||
|
||
```json | ||
# FIXME: 自分のリポジトリに合わせて変更 | ||
"homepage": "https://ryosukedtomita.github.io/react-app", | ||
``` | ||
|
||
## GitHub 側の設定 | ||
|
||
- リポジトリの設定からPages --> Build and deploymentをGitHub Actions を選択する。 | ||
|
||
> [GitHub Pages](https://github.com/RyosukeDTomita/devsecops-demo-aws-ecs/settings/pages) | ||
## github actions の設定 | ||
|
||
dockerでコンテナを作成し,その中でbuildしたものをgithub-pagesに渡している。 | ||
|
||
### GitHub Container Registry にイメージを push する | ||
|
||
- Personal Access Tokenの作成が必用。アカウントの設定ページから,**Developer settings** --> Personal access tokens --> Tokens(classic) --> Generate new token (classic)から作成する([Personal access tokens](https://github.com/settings/tokens))。 | ||
- この際にwrite:packages等の必用な権限をオンにする。自分は一旦以下のように設定。 | ||
![patの設定](./doc/fig/pat-pages.png) | ||
- 表示されたトークンを保存する。自分は環境変数`GITHUBPAT`に保存した。 | ||
- 試しにpushしてPATが有効であることを確認する。 | ||
|
||
```shell | ||
# FIXME: 自分のGitHub Accountに合わせて変更 | ||
# docker build -t ghcr.io/ryosukedtomita/devsecops-demo-aws-ecs:latest . | ||
|
||
echo $GITHUBPAT | docker login ghcr.io -u RyosukeDTomita --password-stdin | ||
docker push ghcr.io/ryosukedtomita/react-app:latest | ||
``` | ||
|
||
- うまくいけば[Packages](https://github.com/RyosukeDTomita?tab=packages)に保存されているはず。 | ||
![packages](./doc/fig/package.png) | ||
|
||
#### GitHub Actions Secrets に PAT を保存 | ||
|
||
- settings --> Secrets and variables --> から変数名`PAT`で Repository secrets を登録する。 | ||
![Alt text](doc/fig/secrets.png) | ||
|
||
## github pagesにデプロイ | ||
|
||
just `git push origin master` and go to your own url set by [package.json](./package.json) | ||
|
||
--- | ||
|
||
## MEMO | ||
|
||
### Branch "master" is not allowed to deploy to github-pages due to environment protection rules | ||
|
||
- github actions の deploy 時に何故が deploy が失敗する。 | ||
- おそらくバグだとおもわれ(2024/02/02),Pages の設定ページの Source を一度 Deploy from a branch に変更して Branch を main から master に変更した後,再度 Source を GitHub Actions に変更したら直った。 |
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
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
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