Skip to content

Commit

Permalink
Merge pull request #2 from hathitrust/deploy-to-testing
Browse files Browse the repository at this point in the history
Add github workflows
  • Loading branch information
aelkiss authored Jul 27, 2022
2 parents 28e2270 + 181d702 commit d042ea5
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 13 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Docker Build

on:
workflow_run:
workflows: [ 'Run CI']
branches: [ 'main' ]
types: [ completed ]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: hathitrust/github_actions/build@v1
with:
image: ghcr.io/hathitrust/oai_solr-unstable
dockerfile: Dockerfile.prod
tag: ${{ github.sha }}
push_latest: true
registry_token: ${{ github.token }}

deploy-staging:
needs: build
runs-on: ubuntu-latest
environment: staging
steps:
- name: Deploy to ${{ env.environment }}
uses: mlibrary/deploy-to-kubernetes@v1
with:
github_username: ${{ github.actor }}
github_token: ${{ secrets.GITHUB_TOKEN }}
image: hathitrust/oai_solr-unstable:${{ github.sha }}
cluster_ca: ${{ secrets.KUBERNETES_CA }}
cluster_server: ${{ secrets.KUBERNETES_SERVER }}
namespace_token: ${{ secrets.KUBERNETES_TOKEN }}
namespace: ${{ secrets.KUBERNETES_NAMESPACE }}
21 changes: 21 additions & 0 deletions .github/workflows/build-manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Manual Image Build

on:
workflow_dispatch:
inputs:
tag:
description: tag
required: true

jobs:
build_manual:
runs-on: ubuntu-latest
steps:
- uses: hathitrust/github_actions/build@v1
with:
dockerfile: Dockerfile.prod
image: ghcr.io/hathitrust/oai_solr-unstable
tag: ${{ github.event.inputs.tag }}
push_latest: false
registry_token: ${{ github.token }}
24 changes: 24 additions & 0 deletions .github/workflows/deploy-production.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Deploy to Production

on:
workflow_dispatch:
inputs:
tag:
description: Release
required: true

jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- name: Deploy to Production
uses: mlibrary/deploy-to-kubernetes@v2
with:
registry_username: ${{ github.actor }}
registry_token: ${{ secrets.GITHUB_TOKEN }}
image: ghcr.io/hathitrust/oai_solr:${{ github.event.inputs.tag }}
cluster_ca: ${{ secrets.KUBERNETES_CA }}
cluster_server: ${{ secrets.KUBERNETES_SERVER }}
namespace_token: ${{ secrets.KUBERNETES_TOKEN }}
namespace: ${{ secrets.KUBERNETES_NAMESPACE }}
49 changes: 49 additions & 0 deletions .github/workflows/manual-deploy-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Manual Deploy to Testing

on:
workflow_dispatch:
inputs:
tag:
description: tag
required: true

env:
environment: testing

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: hathitrust/github_actions/build@v1
with:
dockerfile: Dockerfile.prod
image: ghcr.io/hathitrust/oai_solr-unstable
tag: ${{ github.event.inputs.tag }}
push_latest: false
registry_token: ${{ github.token }}

deploy:
needs: build
runs-on: ubuntu-latest
environment: testing
steps:
# Possible to get this as output from the build job?
- name: Find commit for tag
id: tag_check
uses: hathitrust/github_actions/validate-tag@v1
with:
tag: ${{ github.event.inputs.tag }}
- name: Deploy to ${{ env.environment }}
uses: mlibrary/deploy-to-kubernetes@v1
with:
github_username: ${{ github.actor }}
github_token: ${{ secrets.GITHUB_TOKEN }}
image: hathitrust/oai_solr-unstable:${{ steps.tag_check.outputs.tag }}
cluster_ca: ${{ secrets.KUBERNETES_CA }}
cluster_server: ${{ secrets.KUBERNETES_SERVER }}
namespace_token: ${{ secrets.KUBERNETES_TOKEN }}
namespace: ${{ secrets.KUBERNETES_NAMESPACE }}
16 changes: 16 additions & 0 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Docker Tag Latest Release

on:
release:
types: [ released ]

jobs:
tag-release:
runs-on: ubuntu-latest
steps:
- uses: hathitrust/github_actions/tag-release@v1
with:
registry_token: ${{ github.token }}
existing_tag: ghcr.io/hathitrust/oai_solr-unstable:${{ github.sha }}
image: ghcr.io/hathitrust/oai_solr
new_tag: ${{ github.event.release.tag_name }}
36 changes: 36 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run Tests

on:
push:
branches:
- main

pull_request:

jobs:
# Run tests
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Log in to package registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}


- name: Set up tests
run: |
docker-compose build
docker-compose run web bundle install
- name: Run standardrb
run: docker-compose run web bundle exec standardrb

- name: Run tests
run: docker-compose run web bundle exec rspec

5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ ARG UID=1000
ARG GID=1000

RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
libxerces-c-samples
# nodejs \
# netcat
libxerces-c-samples \
netcat

# COPY Gemfile* /usr/src/app/
WORKDIR /usr/src/app
Expand Down
19 changes: 19 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ruby:3.1
ARG UNAME=app
ARG UID=1000
ARG GID=1000

RUN gem install bundler
RUN groupadd -g $GID -o $UNAME
RUN useradd -m -d /usr/src/app -u $UID -g $GID -o -s /bin/bash $UNAME
RUN mkdir -p /gems && chown $UID:$GID /gems
USER $UNAME
COPY --chown=$UID:$GID Gemfile* /usr/src/app/
WORKDIR /usr/src/app
ENV BUNDLE_PATH /gems
RUN bundle install
COPY --chown=$UID:$GID . /usr/src/app

CMD ["bundle","exec","ruby","oai_solr.rb","-o","0.0.0.0"]

LABEL org.opencontainers.image.source="https://github.com/hathitrust/oai_solr"
23 changes: 13 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ version: '3'

services:

# Uncomment the networks block if you want to connect to solr running
# elsewhere
web:
build: .
ports:
Expand All @@ -15,17 +13,22 @@ services:
command: bundle exec ruby oai_solr.rb -o 0.0.0.0
environment:
SOLR_URL: http://solr-sdr-catalog:9033/solr/catalog
# networks:
# - catalog_indexer
depends_on:
- solr-sdr-catalog

test:
build: .
volumes:
- .:/usr/src/app
- gem_cache:/gems
command: bash -c "bin/wait-for solr-sdr-catalog:9033 && bundle exec rspec"
environment:
SOLR_URL: http://solr-sdr-catalog:9033/solr/catalog
depends_on:
- solr-sdr-catalog

solr-sdr-catalog:
image: ghcr.io/hathitrust/catalog-solr-sample

volumes:
gem_cache:

# networks:
# catalog_indexer:
# external: true
# # Adjust this if the running solr is in another docker network
# name: hathitrust_catalog_indexer_default

0 comments on commit d042ea5

Please sign in to comment.