Advertisement
Guest User

Github Push with RSpec and Docker Build

a guest
Jan 2nd, 2022
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. # ./github/workflows/push.yml
  2. name: Continuous integration
  3. on: push
  4.  
  5. jobs:
  6. test:
  7. runs-on: ubuntu-18.04
  8. # ubuntu-latest will be migrated to 20.04
  9. timeout-minutes: 30
  10.  
  11. services:
  12. postgres:
  13. image: postgres:12-alpine
  14. ports: ["5432:5432"]
  15. env:
  16. POSTGRES_USER: postgres
  17. POSTGRES_PASSWORD: postgres
  18.  
  19. redis:
  20. image: redis:alpine
  21. ports: ["6379:6379"]
  22.  
  23. steps:
  24. - uses: actions/checkout@v1
  25.  
  26. - name: Use Node.js
  27. uses: actions/setup-node@v1
  28. with:
  29. node-version: '12.15.0'
  30.  
  31. - name: Set up Ruby 2.7
  32. uses: actions/setup-ruby@v1
  33. with:
  34. ruby-version: 2.7.x
  35.  
  36. - name: Install PostgreSQL client
  37. run: |
  38. sudo apt-get -yqq install libpq-dev
  39.  
  40. - name: Bundle gems
  41. run: |
  42. gem install bundler -v 2.2.25
  43. bundle config path vendor/bundle
  44. bundle install --jobs 4 --retry 3 --without production development
  45.  
  46. - name: Cache Ruby gems
  47. uses: actions/cache@v1
  48. with:
  49. path: vendor/bundle
  50. key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
  51. restore-keys: |
  52. ${{ runner.os }}-gem-
  53.  
  54. - name: Audit gems
  55. run: bundle exec bundle-audit check --update
  56.  
  57. - name: Lint with RuboCop
  58. run: bundle exec rubocop --parallel
  59.  
  60. - name: Get yarn cache
  61. id: yarn-cache
  62. run: echo "::set-output name=dir::$(yarn cache dir)"
  63.  
  64. - uses: actions/cache@v1
  65. with:
  66. path: ${{ steps.yarn-cache.outputs.dir }}
  67. key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  68. restore-keys: |
  69. ${{ runner.os }}-yarn-
  70.  
  71. - name: Install Node modules
  72. run: yarn install
  73.  
  74. - name: Precompile Assets
  75. run: bin/rails dev:cache && bin/rails assets:precompile
  76.  
  77. - name: Setup Test Database
  78. run: |
  79. cp config/database.yml.github-actions config/database.yml
  80. bin/rails db:create
  81. bin/rails db:migrate
  82. env:
  83. RAILS_ENV: test
  84. POSTGRES_USER: postgres
  85. POSTGRES_PASSWORD: postgres
  86. REDIS_URL: redis://localhost:6379
  87.  
  88. - name: Run Tests
  89. env:
  90. DB_HOST: localhost
  91. DB_USER: postgres
  92. RAILS_ENV: test
  93. POSTGRES_USER: postgres
  94. POSTGRES_PASSWORD: postgres
  95. SECRET_KEY_BASE: we-dont-need-a-secret-here
  96. APP_ADMIN_EMAIL: [email protected]
  97. APP_ADMIN_PASSWORD: secret
  98. APP_EMAIL: [email protected]
  99. APP_HOST: example.org
  100. AWS_ACCESS_KEY_ID: my-access-key
  101. AWS_SECRET_ACCESS_KEY: my-secret
  102. AWS_BUCKET: my-bucket
  103. AWS_REGION: eu-central-1
  104. REDIS_URL: redis://localhost:6379
  105. run: |
  106. bin/rspec
  107.  
  108. # https://docs.github.com/en/actions/guides/publishing-docker-images
  109. - name: Log in to the Container registry
  110. if: github.ref == 'refs/heads/master' && success()
  111. uses: docker/login-action@v1
  112. env:
  113. REGISTRY: ghcr.io
  114. IMAGE_NAME: ${{ github.repository }}
  115. with:
  116. registry: ${{ env.REGISTRY }}
  117. username: ${{ github.actor }}
  118. password: ${{ secrets.GITHUB_TOKEN }}
  119.  
  120. # https://github.com/docker/metadata-action#typesha
  121. - name: Extract metadata (tags, labels) for Docker
  122. if: github.ref == 'refs/heads/master' && success()
  123. id: meta
  124. uses: docker/metadata-action@v3
  125. env:
  126. REGISTRY: ghcr.io
  127. IMAGE_NAME: ${{ github.repository }}
  128. with:
  129. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  130. tags: |
  131. type=schedule,pattern={{date 'YYYYMMDDHHmmss'}}
  132. type=semver,pattern={{version}}
  133. type=sha
  134.  
  135. - name: Setup Development Database
  136. run: |
  137. cp config/database.yml.github-actions config/database.yml
  138. bin/rails db:create
  139. bin/rails db:migrate
  140. env:
  141. RAILS_ENV: development
  142. POSTGRES_USER: postgres
  143. POSTGRES_PASSWORD: postgres
  144. REDIS_URL: redis://localhost:6379
  145.  
  146. - name: Get timestamp
  147. id: date
  148. run: echo "::set-output name=date::$('%Y%m%d%H%M%S%L')"
  149.  
  150. - name: Build and push Docker image
  151. if: github.ref == 'refs/heads/master' && success()
  152. uses: docker/build-push-action@v2
  153. with:
  154. context: .
  155. file: ./Dockerfile
  156. push: true
  157. tags: ${{ steps.meta.outputs.tags }}
  158. labels: ${{ steps.meta.outputs.labels }}
  159. build-args: |
  160. BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
  161. VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
  162. REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement