This repository has been archived by the owner on Jun 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (135 loc) · 4.85 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: ci
on:
push:
branches: [ master ]
pull_request: {}
env:
DOCKER_IMAGE_NAME: app
DOCKER_REGISTRY: docker.io
DOCKER_REGISTRY_USER: doxavore
DOCKER_REPO: doxavore/chasqui
RAILS_ENV: test
jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Set full docker image name
run: echo "::set-env name=FULL_DOCKER_IMAGE::$DOCKER_REPO:$DOCKER_IMAGE_NAME-$GITHUB_SHA"
- name: Build docker image
run: |
docker build -t "$FULL_DOCKER_IMAGE" .
- name: Authenticate to Docker Hub
if: github.repository == env.DOCKER_REPO
run: |
echo "${{ secrets.DOCKER_HUB_KEY }}" | docker login -u $DOCKER_REGISTRY_USER --password-stdin "$DOCKER_REGISTRY"
- name: Push docker image to Docker Hub
if: github.repository == env.DOCKER_REPO
run: |
docker push "$FULL_DOCKER_IMAGE"
- name: Docker log out
if: always()
run: |
docker logout "$DOCKER_REGISTRY"
lint:
needs: build
runs-on: ubuntu-18.04
env:
RAILS_ENV: test
steps:
- name: Set full docker image name
run: echo "::set-env name=FULL_DOCKER_IMAGE::$DOCKER_REPO:$DOCKER_IMAGE_NAME-$GITHUB_SHA"
- name: Pull Docker image
run: |
echo "${{ secrets.DOCKER_HUB_KEY }}" | docker login -u $DOCKER_REGISTRY_USER --password-stdin "$DOCKER_REGISTRY"
docker pull "$FULL_DOCKER_IMAGE"
- name: Run rubocop
run: |
docker run --rm --env RAILS_ENV=$RAILS_ENV "$FULL_DOCKER_IMAGE" bin/rubocop
- name: Run brakeman
run: |
docker run --rm --env RAILS_ENV=$RAILS_ENV "$FULL_DOCKER_IMAGE" bin/brakeman
- name: Check translation health
run: |
docker run --rm --env RAILS_ENV=$RAILS_ENV "$FULL_DOCKER_IMAGE" bin/i18n-tasks health
- name: Docker log out
if: always()
run: |
docker logout "$DOCKER_REGISTRY"
test:
needs: build
runs-on: ubuntu-18.04
services:
postgres:
image: "postgres:11-alpine"
ports:
- "5432:5432"
env:
POSTGRES_USER: "root"
POSTGRES_PASSWORD: "root"
options: >-
--health-cmd pg_isready
--health-interval 1s
--health-timeout 2s
--health-retries 20
redis:
image: "redis:5-alpine"
ports:
- "6379:6379"
env:
POSTGRES_HOST: postgres
RAILS_ENV: test
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
steps:
- name: Set environment
# This doesn't currently work; it's always empty.
# echo ::set-env name=DOCKER_NETWORK::${{ job.services.network }}
run: |
echo "::set-env name=FULL_DOCKER_IMAGE::$DOCKER_REPO:$DOCKER_IMAGE_NAME-$GITHUB_SHA"
echo ::set-env name=DOCKER_NETWORK::$(docker inspect -f '{{.HostConfig.NetworkMode}}' ${{ job.services.postgres.id }})
echo ::set-env name=POSTGRES_ID::${{ job.services.postgres.id }}
echo ::set-env name=POSTGRES_PORT::${{ job.services.postgres.ports[5432] }}
echo ::set-env name=REDIS_URL::redis://redis:${{ job.services.redis.ports[6379] }}
- name: Pull Docker image
run: |
echo "${{ secrets.DOCKER_HUB_KEY }}" | docker login -u $DOCKER_REGISTRY_USER --password-stdin "$DOCKER_REGISTRY"
docker pull "$FULL_DOCKER_IMAGE"
- name: Set up app
run: |
docker run --rm --network "$DOCKER_NETWORK" \
-e RAILS_ENV -e POSTGRES_HOST -e POSTGRES_PORT -e REDIS_URL \
"$FULL_DOCKER_IMAGE" \
bundle exec rails db:setup
- name: Run tests
run: |
docker run --rm --network "$DOCKER_NETWORK" \
-e RAILS_ENV -e POSTGRES_HOST -e POSTGRES_PORT -e REDIS_URL \
"$FULL_DOCKER_IMAGE" \
bundle exec rspec
- name: Docker log out
if: always()
run: |
docker logout "$DOCKER_REGISTRY"
release-candidate:
# Can't seem to use env here?
if: github.repository == 'doxavore/chasqui' && github.head_ref == 'master'
needs:
- build
- lint
- test
runs-on: ubuntu-18.04
steps:
- name: Set full docker image name
run: |
echo "::set-env name=FULL_DOCKER_IMAGE::$DOCKER_REPO:$DOCKER_IMAGE_NAME-$GITHUB_SHA"
echo "::set-env name=LATEST_DOCKER_IMAGE::$DOCKER_REPO:$DOCKER_IMAGE_NAME-latest"
- name: Tag latest docker image
run: |
echo "${{ secrets.DOCKER_HUB_KEY }}" | docker login -u $DOCKER_REGISTRY_USER --password-stdin "$DOCKER_REGISTRY"
docker pull "$FULL_DOCKER_IMAGE"
docker tag "$FULL_DOCKER_IMAGE" "$LATEST_DOCKER_IMAGE"
docker push "$LATEST_DOCKER_IMAGE"
- name: Docker log out
if: always()
run: |
docker logout "$DOCKER_REGISTRY"