-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (129 loc) · 4.05 KB
/
build.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
name: Build
on: [ push, pull_request, workflow_dispatch ]
env:
REGISTRY: ghcr.io
jobs:
# TODO: DRY w/release.yml
setup:
runs-on: ubuntu-latest
steps:
# See https://github.com/docker/build-push-action/blob/v2.10.0/TROUBLESHOOTING.md#repository-name-must-be-lowercase
- name: Sanitize image name
uses: actions/github-script@v6
id: image-name
with:
result-encoding: string
script: return '${{ env.REGISTRY }}/${{ github.repository }}'.toLowerCase()
- name: Get short SHA
run: |
echo SHORT_SHA="${GITHUB_SHA:0:7}" >> $GITHUB_ENV
outputs:
base_image_name: ${{ steps.image-name.outputs.result }}
build_image: ${{ steps.image-name.outputs.result }}:${{ env.SHORT_SHA }}
build:
if: github.event_name != 'release'
needs: setup
env:
BUILD_IMAGE: ${{ needs.setup.outputs.build_image }}
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get build start time
run: |
echo BUILD_TIMESTAMP="$(date --utc --iso-8601=seconds)" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ env.BUILD_IMAGE }}
build-args: |
BUILD_TIMESTAMP=${{ env.BUILD_TIMESTAMP }}
BUILD_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
DOCKER_TAG=${{ env.BUILD_IMAGE }}
GIT_BRANCH=${{ github.ref_name }}
GIT_COMMIT=${{ github.sha }}
GIT_URL=${{ github.repositoryUrl }}
outputs:
build_image: ${{ env.BUILD_IMAGE }}
test:
if: github.event_name != 'release'
needs: build
runs-on: ubuntu-latest
container:
options: --init
image: ${{ needs.build.outputs.build_image }}
defaults:
run:
working-directory: /opt/app
services:
db:
image: postgres
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
# solr:
# image: solr:8
# #restart: always
# ports:
# - 8983:8983
# volumes:
# - ${{ github.workspace }}/solr:/var/solr/data/configsets/solr:delegated
steps:
- name: Run tests
env:
RAILS_ENV: test
run: bundle exec rake check -t
- name: Run style checks
run: bundle exec rubocop
- name: Validate database migrations
env:
RAILS_ENV: test
DISABLE_DATABASE_ENVIRONMENT_CHECK: 1
run: rails --trace db:drop db:create db:migrate
- name: Upload artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
/opt/app/artifacts/**
/tmp/solr*/server/logs
# TODO: DRY w/release.yml
push:
if: github.event_name != 'release'
needs: [ setup, build, test ]
env:
BASE_IMAGE_NAME: ${{ needs.setup.outputs.base_image_name }}
BUILD_IMAGE: ${{ needs.build.outputs.build_image }}
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.BASE_IMAGE_NAME }}
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Tag and push image
uses: akhilerm/tag-push-action@v2.1.0
with:
src: ${{ env.BUILD_IMAGE }}
dst: |
${{ steps.meta.outputs.tags }}