Skip to content

Commit 8405887

Browse files
authored
Merge pull request #784 from dev-hato/add_deploy_ci
GitHub Packagesへのデプロイ用CI追加
2 parents a52f883 + 5bf8df5 commit 8405887

3 files changed

Lines changed: 78 additions & 45 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

.github/workflows/pr-test-hato-bot.yml

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -63,48 +63,3 @@ jobs:
6363
- name: Test
6464
run: |
6565
pipenv run python -m unittest
66-
67-
pr-docker:
68-
runs-on: ubuntu-latest
69-
70-
steps:
71-
- uses: actions/checkout@v2
72-
with:
73-
fetch-depth: 0
74-
- name: Set .env
75-
run: |
76-
cp .env.example .env
77-
- name: Build docker image
78-
env:
79-
DOCKER_BUILDKIT: 1
80-
COMPOSE_DOCKER_CLI_BUILD: 1
81-
working-directory: ./setup
82-
run: docker-compose build --no-cache
83-
- name: Start docker
84-
working-directory: ./setup
85-
run: |
86-
docker-compose up -d
87-
# Dockerコンテナ立ち上げから2分以内に疎通できるようになるかテストする
88-
- name: Test
89-
working-directory: ./setup
90-
run: |
91-
cmd="curl -XPOST -d '{\"message\": \"help\"}'"
92-
cmd+=" -H \"Content-Type: application/json\""
93-
cmd+=" http://localhost:3000/healthcheck"
94-
cmd_="${cmd} -w '%{http_code}' -o /dev/null -s"
95-
start_unixtime=$(date +%s)
96-
97-
while [ "$(echo "$(date +%s) - ${start_unixtime}" | bc)" -lt 120 ] \
98-
&& (! (docker-compose ps | grep -q Exit))
99-
do
100-
if [ "$(eval "${cmd_}")" = 200 ] && eval "${cmd}"
101-
then
102-
docker-compose logs
103-
exit 0
104-
fi
105-
106-
sleep 1
107-
done
108-
109-
docker-compose logs
110-
exit 1

setup/docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ services:
88
build:
99
dockerfile: ./Dockerfile
1010
context: ./pgsql
11+
cache_from:
12+
- ghcr.io/dev-hato/hato-bot/postgres:${TAG_NAME}
13+
- ghcr.io/dev-hato/hato-bot/postgres
14+
image: ghcr.io/dev-hato/hato-bot/postgres:${TAG_NAME}
1115
environment:
1216
POSTGRES_PASSWORD: password
1317
restart: always
@@ -20,6 +24,10 @@ services:
2024
build:
2125
dockerfile: ./Dockerfile
2226
context: ../
27+
cache_from:
28+
- ghcr.io/dev-hato/hato-bot/hato-bot:${TAG_NAME}
29+
- ghcr.io/dev-hato/hato-bot/hato-bot
30+
image: ghcr.io/dev-hato/hato-bot/hato-bot:${TAG_NAME}
2331
env_file:
2432
- ../.env
2533
restart: always

0 commit comments

Comments
 (0)