Skip to content

Commit

Permalink
oidc
Browse files Browse the repository at this point in the history
  • Loading branch information
yamatatsu committed Jul 7, 2022
1 parent a32182f commit 250f417
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Developers IO を書くためのリポジトリ。
## バックログ

- [x] アイキャッチに対応する
- [ ] 新規記事がエラーになる
- [ ] 画像に対応する
- [ ] slugの変更に対応する
- [ ] GHAの整備
Expand Down
42 changes: 42 additions & 0 deletions articles/2022-07-07-circleci-orb-oidc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: CircleCIで、Orbを使ってOIDCする
description: Orbでサクッと書けるようになってたのでやってみた
slug: circleci-orb-oidc
thumbnailId: 455150 # CircleCI
published: true
postCode: 906278
---

こちらの若槻さんの記事のあとに

https://dev.classmethod.jp/articles/circleci-supported-oidc-so-i-tried-linking-it-with-aws/

公式より、新しいaws-cliのOrbでOIDCをサポートするようになったと発表されていたので試してみた。

<iframe class="hatenablogcard" style="width:100%;height:155px;max-width:680px;" title="aws-cli" src="https://hatenablog-parts.com/embed?url=https://discuss.circleci.com/t/openid-connect-support-added-to-aws-cli-orb-v3-1/43817" width="300" height="150" frameborder="0" scrolling="no"></iframe>

## CircleCIの設定

```yaml
orbs:
# use over v3.1 for OIDC
aws-cli: circleci/[email protected]

commands:
deploy:
steps:
# これだけ!!
- aws-cli/setup:
profile-name: WEB-IDENTITY-PROFILE
role-arn: arn:aws:iam::123456789012:role/your-role-name
role-session-name: deploy-session
aws-region: ap-northeast-1 # 環境変数 AWS_DEFAULT_REGION が設定されていれば不要
# もうAWSコマンドたたけちゃう
- run:
name: Get caller identity
command: aws sts get-caller-identity --profile WEB-IDENTITY-PROFILE
```
`role-arn:` には作成した正しいrole名を渡してください。

便利!!!
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"prepublish": "rm -rf ./screenshots/*",
"publish": "env CHANGED_ARTICLES=\"$(git diff --name-only | xargs)\" npx playwright test"
"publish": "env CHANGED_ARTICLES=\"$(git add -N ./articles && git diff --name-only | xargs)\" npx playwright test"
},
"keywords": [],
"author": "",
Expand Down
12 changes: 8 additions & 4 deletions tests/publish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const schema = zod.object({
markdown: zod.string(),
});

test.setTimeout(60_000);

test.beforeEach(async ({ page }) => {
const wpPage = new WPPage(page);
await wpPage.login();
Expand Down Expand Up @@ -56,6 +58,8 @@ test("publish articles", async ({ page }) => {

await wpPage.fill(title, wpContent, description);

await screenshot("after-filled");

if (!postCode) {
await wpPage.save();
const newPostCode = await wpPage.getPostCode();
Expand Down Expand Up @@ -86,9 +90,9 @@ const screenthotter = (page: Page) => {
let num = 0;
return async (name: string) => {
const id = num.toString().padStart(2, "0");
await page.screenshot({
path: `screenshots/${id}-${name}.png`,
});
const path = `screenshots/${id}-${name}.png`;
await page.screenshot({ path });
console.info(`Captured: ${path}`);
num++;
};
};
Expand All @@ -97,7 +101,7 @@ const langMap: Record<string, string> = {
ts: "typescript",
};
const replaceWPCode = (markdown: string) =>
markdown.replace(/```(ts|typescript)[\s\S]*?```/g, (codeBlock, shortLang) => {
markdown.replace(/```(\w+)[\s\S]*?```/g, (codeBlock, shortLang) => {
const lang = langMap[shortLang] ?? shortLang;
return codeBlock
.replace(/^```\w+/, `[${lang}]`)
Expand Down

0 comments on commit 250f417

Please sign in to comment.