forked from inno-devops-labs/DevOps-Core-Course
-
Notifications
You must be signed in to change notification settings - Fork 1
119 lines (101 loc) · 3.12 KB
/
app_ruby.yml
File metadata and controls
119 lines (101 loc) · 3.12 KB
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
name: CI for app_ruby
on:
push:
paths:
- 'app_ruby/**'
- '.github/workflows/app_ruby.yml'
pull_request:
paths:
- 'app_ruby/**'
- '.github/workflows/app_ruby.yml'
defaults:
run:
working-directory: app_ruby
jobs:
lint_and_format:
timeout-minutes: 2
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4'
bundler-cache: true
- name: Install dependencies
run: |
gem install bundler
bundle install
- name: Run RuboCop
run: bundle exec rubocop -A
test:
timeout-minutes: 2
runs-on: ubuntu-22.04
needs: lint_and_format
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4'
bundler-cache: true
- name: Install dependencies
run: |
gem install bundler
bundle install
- name: Run tests
run: bundle exec rspec
security_scan:
timeout-minutes: 5
runs-on: ubuntu-22.04
needs: [lint_and_format, test]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/ruby@master
continue-on-error: true
with:
args: --skip-unresolved app_ruby/
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
docker_build_and_push:
timeout-minutes: 10
runs-on: ubuntu-22.04
needs: [lint_and_format, test, security_scan]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get short commit hash
id: commit
run: echo "SHORT_COMMIT_HASH=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
registry: docker.io
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: "{{defaultContext}}:app_ruby"
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/omsk-time:${{ env.SHORT_COMMIT_HASH }}
${{ secrets.DOCKERHUB_USERNAME }}/omsk-time:${{ env.SHORT_COMMIT_HASH }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
cache-from: type=gha,type=registry,ref=ghcr.io/${{ github.repository_owner }}/omsk-time:buildcache
cache-to: type=gha,mode=max,type=registry,ref=ghcr.io/${{ github.repository_owner }}/omsk-time:buildcache,mode=max