Skip to content

Commit

Permalink
Workflows.
Browse files Browse the repository at this point in the history
  • Loading branch information
svogt0511 committed Dec 13, 2023
1 parent e0ea4f4 commit a3e3ad5
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 59 deletions.
27 changes: 7 additions & 20 deletions .github/workflows/_update_terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
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
Expand All @@ -13,26 +17,16 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
env:
GIT_SHA: ${{ github.sha }}
GIT_TAG: ${{ inputs.image_tag }}
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: 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
Expand All @@ -42,27 +36,20 @@ jobs:
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: |
export GIT_SHA=${{ steps.extract_variables.outputs.GIT_SHA_SHORT }}
export GIT_TAG=${{ steps.extract_variables.outputs.GIT_TAG }}
./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: |
export GIT_SHA=${{ steps.extract_variables.outputs.GIT_SHA_SHORT }}
export GIT_TAG=${{ steps.extract_variables.outputs.GIT_TAG }}
./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/[email protected]
with:
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/branch_to_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ jobs:
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]
Expand Down
29 changes: 13 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ on:
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
Expand All @@ -32,27 +41,15 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get git tag
run: |
echo "GIT_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_OUTPUT
id: set_git_vars
- name: Push to Docker Hub
- name: Build and Push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ github.repository }}:latest
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
- name: Push to GitHub Packages
uses: docker/build-push-action@v4
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
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ jobs:
call_build_and_push:
needs: test
uses: ./.github/workflows/build.yml
with:
image_name: ${{ github.repository }}
image_tag: main
secrets: inherit
deploy:
needs: [test, call_build_and_push]
uses: ./.github/workflows/_update_terraform.yml
with:
image_tag: main
deployment_environment: staging
secrets: inherit
6 changes: 3 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Test Pull Request
on:
# pull_request:
# branches:
# - master
pull_request:
branches:
- master
workflow_dispatch:
jobs:
test:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ jobs:
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: production
secrets: inherit
10 changes: 10 additions & 0 deletions .github/workflows/reset_staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Reset Staging to Main Branch
on:
workflow_dispatch:
jobs:
deploy:
uses: ./.github/workflows/_update_terraform.yml
with:
image_tag: main
deployment_environment: staging
secrets: inherit
17 changes: 0 additions & 17 deletions .github/workflows/test-branch.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .github/workflows/test_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Test Branch
on:
workflow_dispatch:
jobs:
test:
uses: ./.github/workflows/ci.yml
secrets: inherit

0 comments on commit a3e3ad5

Please sign in to comment.