|
| 1 | +--- |
| 2 | +name: deploy |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + pull_request: |
| 9 | + |
| 10 | +jobs: |
| 11 | + deploy_docker_image: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + defaults: |
| 14 | + run: |
| 15 | + working-directory: setup |
| 16 | + env: |
| 17 | + DOCKER_BUILDKIT: 1 |
| 18 | + COMPOSE_DOCKER_CLI_BUILD: 1 |
| 19 | + permissions: |
| 20 | + packages: write |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v2 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + - name: Set .env |
| 26 | + run: cp .env.example .env |
| 27 | + working-directory: . |
| 28 | + - name: Login to GitHub Container Registry |
| 29 | + uses: docker/login-action@v1 |
| 30 | + with: |
| 31 | + registry: ghcr.io |
| 32 | + username: ${{ github.actor }} |
| 33 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + - name: Set up Docker Buildx |
| 35 | + id: buildx |
| 36 | + uses: docker/setup-buildx-action@v1 |
| 37 | + - run: echo "TAG_NAME=${HEAD_REF//\//-}" >> "$GITHUB_ENV" |
| 38 | + env: |
| 39 | + HEAD_REF: ${{github.head_ref}} |
| 40 | + if: ${{ github.event_name == 'pull_request' }} |
| 41 | + - run: echo 'TAG_NAME=latest' >> "$GITHUB_ENV" |
| 42 | + if: ${{ github.event_name == 'push' }} |
| 43 | + - name: Build docker image |
| 44 | + run: docker-compose build --build-arg BUILDKIT_INLINE_CACHE=1 |
| 45 | + - name: Start docker |
| 46 | + run: docker-compose up -d |
| 47 | + # Dockerコンテナ立ち上げから2分以内に疎通できるようになるかテストする |
| 48 | + - name: Test |
| 49 | + run: | |
| 50 | + cmd="curl -XPOST -d '{\"message\": \"help\"}'" |
| 51 | + cmd+=" -H \"Content-Type: application/json\"" |
| 52 | + cmd+=" http://localhost:3000/healthcheck" |
| 53 | + cmd_="${cmd} -w '%{http_code}' -o /dev/null -s" |
| 54 | + start_unixtime=$(date +%s) |
| 55 | +
|
| 56 | + while [ "$(echo "$(date +%s) - ${start_unixtime}" | bc)" -lt 120 ] \ |
| 57 | + && (! (docker-compose ps | grep -q Exit)) |
| 58 | + do |
| 59 | + if [ "$(eval "${cmd_}")" = 200 ] && eval "${cmd}" |
| 60 | + then |
| 61 | + docker-compose logs |
| 62 | + exit 0 |
| 63 | + fi |
| 64 | +
|
| 65 | + sleep 1 |
| 66 | + done |
| 67 | +
|
| 68 | + docker-compose logs |
| 69 | + exit 1 |
| 70 | + - run: docker-compose push |
0 commit comments