Skip to content

Commit

Permalink
Merge pull request #65 from datacite/schema-4.5b
Browse files Browse the repository at this point in the history
Finish updating github workflows and restructure them similar to othe…
  • Loading branch information
svogt0511 authored Dec 13, 2023
2 parents 9989261 + 3bb8daa commit 678390a
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 304 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/_update_terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Update Terraform
on:
workflow_call:
secrets:
PERSONAL_ACCESS_TOKEN:
required: true
inputs:
image_tag:
description: Tag for the image for docker/ghcr registries
required: true
type: string
deployment_environment:
description: The terraform target environment
required: true
type: string
default: staging
jobs:
deploy:
runs-on: ubuntu-latest
env:
GIT_SHA: ${{ github.sha }}
GIT_TAG: ${{ inputs.image_tag }}
steps:
- name: Checkout terraform config repo
uses: actions/checkout@v3
with:
# public repo with terraform configuration
repository: 'datacite/mastino'
persist-credentials: false
- name: Setup dockerize and template parameters
# use go template in terraform config repository to update git sha and tag
# commit and push changes to trigger terraform workflow
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
wget https://github.com/jwilder/dockerize/releases/download/v0.6.0/dockerize-linux-amd64-v0.6.0.tar.gz
tar -xzvf dockerize-linux-amd64-v0.6.0.tar.gz
rm dockerize-linux-amd64-v0.6.0.tar.gz
- name: Conditionally update staging environment
if: ${{ (inputs.deployment_environment == 'staging') }}
run: |
./dockerize -template stage/services/mds/_poodle.auto.tfvars.tmpl:stage/services/mds/_poodle.auto.tfvars
git add stage/services/mds/_poodle.auto.tfvars
git commit -m "Adding poodle git variables for commit ${{ steps.extract_variables.outputs.GIT_SHA }}"
- name: Conditionally update production/test environments
if: ${{ (inputs.deployment_environment == 'production') }}
run: |
./dockerize -template prod-eu-west/services/mds/_poodle.auto.tfvars.tmpl:prod-eu-west/services/mds/_poodle.auto.tfvars
./dockerize -template test/services/mds/_poodle.auto.tfvars.tmpl:test/services/mds/_poodle.auto.tfvars
git add prod-eu-west/services/mds/_poodle.auto.tfvars
git add test/services/mds/_poodle.auto.tfvars
git commit -m "Adding poodle git variables for tag ${{ steps.extract_variables.outputs.GIT_TAG }}"
- name: Push changes
uses: ad-m/github-push-action@v0.7.0
with:
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
repository: 'datacite/mastino'
branch: 'refs/heads/master'
tags: false
21 changes: 21 additions & 0 deletions .github/workflows/branch_to_staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build/Deploy Branch to Staging
on:
workflow_dispatch:
jobs:
test:
uses: ./.github/workflows/ci.yml
secrets: inherit
call_build_and_push:
needs: test
uses: ./.github/workflows/build.yml
with:
image_name: ${{ github.repository }}
image_tag: ${{ github.ref_name }}
secrets: inherit
deploy:
needs: [test, call_build_and_push]
uses: ./.github/workflows/_update_terraform.yml
with:
image_tag: ${{ github.ref_name }}
deployment_environment: staging
secrets: inherit
55 changes: 55 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build and Tag
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true
inputs:
image_name:
description: The name of the image for docker/ghcr registries
required: true
type: string
image_tag:
description: Tag for the image for docker/ghcr registries
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ inputs.image_name }}:${{ inputs.image_tag }}
ghcr.io/${{ inputs.image_name }}:${{ inputs.image_tag }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
# no-cache: true
20 changes: 16 additions & 4 deletions .github/workflows/test-branch.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
name: Test Branch
name: CI
on:
workflow_dispatch:

workflow_call:
secrets:
MDS_USERNAME:
required: true
MDS_PASSWORD:
required: true
CC_TEST_REPORTER_ID:
required: true
jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -27,14 +33,20 @@ jobs:
restore-keys: |
${{ runner.os }}-gems-
- name: Install
env:
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
run: |
gem install bundler
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Lint and Test
- name: (Lint and) Test
env:
MEMCACHE_SERVERS: "localhost:11211"
run: |
# bundle exec rubocop
bundle exec rspec
echo $?
- name: Publish code coverage
uses: paambaati/codeclimate-action@v3.1.1
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
160 changes: 15 additions & 145 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,153 +1,23 @@
name: Deploy
name: Deploy Main to Staging
on:
push:
branches:
- "master"
jobs:
test:
runs-on: ubuntu-latest
services:
memcached:
image: memcached:1.4.31
ports:
- 11211/udp
env:
MEMCACHE_SERVERS: "localhost:11211"
MDS_USERNAME: ${{ secrets.MDS_USERNAME }}
MDS_PASSWORD: ${{ secrets.MDS_PASSWORD }}
steps:
- uses: actions/checkout@v3
- name: Set up Ruby 2.6
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.6.9'
- uses: actions/cache@v3
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install
run: |
gem install bundler
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Lint and Test
env:
MEMCACHE_SERVERS: "localhost:11211"
run: |
# bundle exec rubocop
bundle exec rspec
echo $?
- name: Publish code coverage
uses: paambaati/codeclimate-action@v3.1.1
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

build:
uses: ./.github/workflows/ci.yml
secrets: inherit
call_build_and_push:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to Docker Hub
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ github.repository }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
# no-cache: true
- name: Push to GitHub Packages
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ghcr.io/${{ github.repository }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
# no-cache: true

uses: ./.github/workflows/build.yml
with:
image_name: ${{ github.repository }}
image_tag: main
secrets: inherit
deploy:
needs: [test, build]
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Extract variables
shell: bash
run: |
echo "BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" >> $GITHUB_OUTPUT
echo "TAG=$(git tag --points-at HEAD)" >> $GITHUB_OUTPUT
echo "GIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "GIT_SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
id: extract_variables

- name: Checkout terraform config repo
uses: actions/checkout@v3
with:
# public repo with terraform configuration
repository: 'datacite/mastino'
persist-credentials: false
- name: Commit changes to terraform config repository
# use go template in terraform config repository to update git sha and tag
# commit and push changes to trigger terraform workflow
run: |
export GIT_SHA=${{ steps.extract_variables.outputs.GIT_SHA_SHORT }}
export GIT_TAG=${{ steps.extract_variables.outputs.GIT_TAG }}
wget https://github.com/jwilder/dockerize/releases/download/v0.6.0/dockerize-linux-amd64-v0.6.0.tar.gz
tar -xzvf dockerize-linux-amd64-v0.6.0.tar.gz
rm dockerize-linux-amd64-v0.6.0.tar.gz
./dockerize -template stage/services/mds/_poodle.auto.tfvars.tmpl:stage/services/mds/_poodle.auto.tfvars
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add stage/services/mds/_poodle.auto.tfvars
git commit -m "Adding poodle git variables for commit ${{ steps.extract_variables.outputs.GIT_SHA }}"
- name: Push changes
uses: ad-m/github-push-action@v0.6.0
with:
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
repository: 'datacite/mastino'
branch: 'refs/heads/master'
tags: false

- name: Notify Slack
uses: edge/simple-slack-notify@master
with:
channel: '#ops'
color: 'good'
text: 'A new version of the <https://mds.stage.datacite.org|MDS API> is been deployed to stage.'
failure_text: '${env.GITHUB_WORKFLOW} (${env.GITHUB_RUN_NUMBER}) build failed'
fields: |
[{ "title": "Commit message", "value": "${{ github.event.head_commit.message }}" },
{ "title": "Committed by", "value": "<https://github.com/${{ github.repository }}/commits?author=${{ github.actor }}|${{ github.actor }}>", "short": true },
{ "title": "Commit SHA", "value": "<https://github.com/${{ github.repository }}/commit/${{ steps.extract_variables.outputs.GIT_SHA }}|${{ steps.extract_variables.outputs.GIT_SHA_SHORT }}>", "short": true },
{ "title": "Repository", "value": "<https://github.com/${{ github.repository }}|${{ github.repository }}>", "short": true },
{ "title": "Branch", "value": "<https://github.com/${{ github.repository }}/tree/${{ steps.extract_variables.outputs.BRANCH }}|${{ steps.extract_variables.outputs.BRANCH }}>", "short": true }]
needs: [test, call_build_and_push]
uses: ./.github/workflows/_update_terraform.yml
with:
image_tag: main
deployment_environment: staging
secrets: inherit
11 changes: 11 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Test Pull Request
on:
pull_request:
branches:
- master
workflow_dispatch:
jobs:
test:
uses: ./.github/workflows/ci.yml
secrets: inherit

Loading

0 comments on commit 678390a

Please sign in to comment.