Update the Docker build workflow to use premade actions so we can cache the build. https://github.com/docker/setup-buildx-action https://github.com/docker/login-action https://github.com/docker/metadata-action https://github.com/docker/build-push-action
144 lines
6.0 KiB
YAML
144 lines
6.0 KiB
YAML
name: Github
|
|
|
|
# Trigger on pushes to master or pull requests to master, but not both.
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
pull_request:
|
|
branches:
|
|
- master
|
|
|
|
jobs:
|
|
# Build Docker image and push to Github Container Registry.
|
|
#
|
|
# https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry
|
|
# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions
|
|
# https://docs.github.com/en/actions/guides/publishing-docker-images
|
|
docker:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
# https://github.com/docker/setup-buildx-action
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v1
|
|
|
|
# https://github.com/docker/login-action
|
|
- name: Login to Github Container Registry
|
|
uses: docker/login-action@v1
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ github.token }}
|
|
|
|
# Generate Docker tags from Git tags.
|
|
# https://github.com/docker/metadata-action
|
|
- name: Generate Docker tags
|
|
uses: docker/metadata-action@v3
|
|
id: metadata
|
|
with:
|
|
images: ghcr.io/${{ github.repository }}
|
|
tags: |
|
|
type=sha,format=short,prefix=
|
|
type=ref,event=branch
|
|
type=ref,event=tag
|
|
type=ref,event=pr
|
|
# Tag `latest` on every commit pushed to master
|
|
# https://github.com/docker/metadata-action/issues/112
|
|
flavor: |
|
|
latest=${{ github.ref == 'refs/heads/master' }}
|
|
|
|
# https://github.com/docker/build-push-action
|
|
- name: Build image
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
push: true
|
|
tags: ${{ steps.metadata.outputs.tags }}
|
|
labels: ${{ steps.metadata.outputs.labels }}
|
|
|
|
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#registry-cache
|
|
# https://dev.to/pst418/speed-up-multi-stage-docker-builds-in-ci-cd-with-buildkit-s-registry-cache-11gi
|
|
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache
|
|
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max
|
|
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
container: ubuntu:20.10
|
|
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
|
|
env:
|
|
DEBIAN_FRONTEND: noninteractive
|
|
PARALLEL_WORKERS: 8 # number of parallel tests to run
|
|
RUBYOPT: -W0 # silence ruby warnings
|
|
VIPS_WARNING: 0 # silence libvips warnings
|
|
|
|
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
|
|
|
DATABASE_URL: postgresql://danbooru:danbooru@postgres/danbooru
|
|
ARCHIVE_DATABASE_URL: postgresql://danbooru:danbooru@postgres/danbooru
|
|
DANBOORU_SECRET_KEY_BASE: 1234
|
|
DANBOORU_AWS_SQS_ENABLED: false
|
|
DANBOORU_TWITTER_API_KEY: ${{ secrets.DANBOORU_TWITTER_API_KEY }}
|
|
DANBOORU_TWITTER_API_SECRET: ${{ secrets.DANBOORU_TWITTER_API_SECRET }}
|
|
DANBOORU_PIXIV_PHPSESSID: ${{ secrets.DANBOORU_PIXIV_PHPSESSID }}
|
|
DANBOORU_NIJIE_LOGIN: ${{ secrets.DANBOORU_NIJIE_LOGIN }}
|
|
DANBOORU_NIJIE_PASSWORD: ${{ secrets.DANBOORU_NIJIE_PASSWORD }}
|
|
DANBOORU_NICO_SEIGA_LOGIN: ${{ secrets.DANBOORU_NICO_SEIGA_LOGIN }}
|
|
DANBOORU_NICO_SEIGA_PASSWORD: ${{ secrets.DANBOORU_NICO_SEIGA_PASSWORD }}
|
|
DANBOORU_TUMBLR_CONSUMER_KEY: ${{ secrets.DANBOORU_TUMBLR_CONSUMER_KEY }}
|
|
DANBOORU_DEVIANTART_CLIENT_ID: ${{ secrets.DANBOORU_DEVIANTART_CLIENT_ID }}
|
|
DANBOORU_DEVIANTART_CLIENT_SECRET: ${{ secrets.DANBOORU_DEVIANTART_CLIENT_SECRET }}
|
|
DANBOORU_PAWOO_CLIENT_ID: ${{ secrets.DANBOORU_PAWOO_CLIENT_ID }}
|
|
DANBOORU_PAWOO_CLIENT_SECRET: ${{ secrets.DANBOORU_PAWOO_CLIENT_SECRET }}
|
|
DANBOORU_BARAAG_CLIENT_ID: ${{ secrets.DANBOORU_BARAAG_CLIENT_ID }}
|
|
DANBOORU_BARAAG_CLIENT_SECRET: ${{ secrets.DANBOORU_BARAAG_CLIENT_SECRET }}
|
|
DANBOORU_DISCORD_WEBHOOK_ID: ${{ secrets.DANBOORU_DISCORD_WEBHOOK_ID }}
|
|
DANBOORU_DISCORD_WEBHOOK_SECRET: ${{ secrets.DANBOORU_DISCORD_WEBHOOK_SECRET }}
|
|
DANBOORU_RAKISMET_KEY: ${{ secrets.DANBOORU_RAKISMET_KEY }}
|
|
DANBOORU_RAKISMET_URL: ${{ secrets.DANBOORU_RAKISMET_URL }}
|
|
DANBOORU_IP_REGISTRY_API_KEY: ${{ secrets.DANBOORU_IP_REGISTRY_API_KEY }}
|
|
DANBOORU_GOOGLE_CLOUD_CREDENTIALS: ${{ secrets.DANBOORU_GOOGLE_CLOUD_CREDENTIALS }}
|
|
DANBOORU_STRIPE_SECRET_KEY: ${{ secrets.DANBOORU_STRIPE_SECRET_KEY }}
|
|
DANBOORU_STRIPE_PUBLISHABLE_KEY: ${{ secrets.DANBOORU_STRIPE_PUBLISHABLE_KEY }}
|
|
DANBOORU_STRIPE_WEBHOOK_SECRET: ${{ secrets.DANBOORU_STRIPE_WEBHOOK_SECRET }}
|
|
DANBOORU_STRIPE_GOLD_USD_PRICE_ID: ${{ secrets.DANBOORU_STRIPE_GOLD_USD_PRICE_ID }}
|
|
DANBOORU_STRIPE_GOLD_EUR_PRICE_ID: ${{ secrets.DANBOORU_STRIPE_GOLD_EUR_PRICE_ID }}
|
|
DANBOORU_STRIPE_PLATINUM_USD_PRICE_ID: ${{ secrets.DANBOORU_STRIPE_PLATINUM_USD_PRICE_ID }}
|
|
DANBOORU_STRIPE_PLATINUM_EUR_PRICE_ID: ${{ secrets.DANBOORU_STRIPE_PLATINUM_EUR_PRICE_ID }}
|
|
DANBOORU_STRIPE_GOLD_TO_PLATINUM_USD_PRICE_ID: ${{ secrets.DANBOORU_STRIPE_GOLD_TO_PLATINUM_USD_PRICE_ID }}
|
|
DANBOORU_STRIPE_GOLD_TO_PLATINUM_EUR_PRICE_ID: ${{ secrets.DANBOORU_STRIPE_GOLD_TO_PLATINUM_EUR_PRICE_ID }}
|
|
|
|
services:
|
|
postgres:
|
|
image: evazion/postgres
|
|
env:
|
|
POSTGRES_USER: danbooru
|
|
POSTGRES_PASSWORD: danbooru
|
|
|
|
steps:
|
|
- name: Install OS dependencies
|
|
run: |
|
|
apt-get update
|
|
apt-get -y install --no-install-recommends build-essential ruby ruby-dev ruby-bundler git nodejs yarnpkg webpack ffmpeg mkvtoolnix libvips-dev libxml2-dev libxslt-dev zlib1g-dev postgresql-server-dev-all wget curl git
|
|
ln -sf /usr/bin/yarnpkg /usr/bin/yarn
|
|
|
|
- name: Check out code
|
|
uses: actions/checkout@v2
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install Ruby dependencies
|
|
run: BUNDLE_DEPLOYMENT=true bundle install --jobs 4
|
|
|
|
- name: Install Javascript dependencies
|
|
run: yarn install
|
|
|
|
- name: Prepare database
|
|
run: config/docker/prepare-tests.sh
|
|
|
|
- name: Run tests
|
|
run: bin/rails test
|