LoginSignup
1
1

More than 3 years have passed since last update.

新しいGitHubActionsでpushしたのをトリガーにswaggerに反映

Last updated at Posted at 2019-05-27

はじめに

swaggerをチームメンバーにリアルタイムで反映する方法がわからなかったので、
この際、新しいバージョンになったGithubActionを使用して、
pushしたものをトリガーに反映させようと思います。

GitHubActionsとは

簡単に言えば、githubのaction(pushやブランチ作成)をトリガーに、
自作で作ったdockerImageでも公式で用意されているdockerImageを使って、
なんでも好きな事ができるよっていう機能です。
詳しいことは、ググってください。(2019/5/4現在ベータ版なので申請が必要です)

方法

Githubのレポジトリに.githubディレクトリを作成し、
その中にmain.workflowファイルを作成する

今回の場合Awsのs3にファイルをアップロードすることを想定しています。

github/workflows/main.yml
name: S3-action
on:
  push:
    branches:    
      - master

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - name: Checkout Repo
      uses: actions/checkout@master
    - uses: actions/aws/cli@master
    - name: s3 push
      env:
        AWS_ACCESS_KEY_ID: "<アクセスキー>"
        AWS_SECRET_ACCESS_KEY: "<シークレットキー>"
      run: aws s3 sync --delete . s3://<S3バケット名>/$GITHUB_REPOSITORY/ --exclude \"*\" --include \"*.yaml\"

バケットを作成し、https://swagger.io/tools/swagger-ui/download/ から、
css,htmlをダウンロードしてバケットのルートディレクトリにコピーする

ip制限したければバケットをhostingしてバケットポリシーを指定してip制限する

{
    "Version": "2012-10-17",
    "Id": "Policy1551163444222",
    "Statement": [
        {
            "Sid": "Stmt1551163442413",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::<バケット名>/*",
            "Condition": {
                "NotIpAddress": {
                    "aws:SourceIp": "ipアドレス"
                }
            }
        },
        {
            "Sid": "Stmt1551164678580",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::<バケット名>/*",
            "Condition": {
                "IpAddress": {
                    "aws:SourceIp": "<ipアドレス>"
                }
            }
        }
    ]
}

http://hostingアドレス/<ユーザ名 or オーガナイゼーション名>/レポジトリ名/swagger.yaml
のアドレスでアクセスできるようになります。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1