Skip to content

Commit

Permalink
feat(workflow): Add mysql/postgres setup workflow (datahub-project#3090)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexter Lee authored and Rahul Jain committed Aug 31, 2021
1 parent 5a0f85f commit 55c5c5c
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 2 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/docker-mysql-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: mysql-setup docker
on:
push:
branches:
- master
paths-ignore:
- 'docs/**'
- '**.md'
pull_request:
branches:
- master
paths:
- './docker/mysql-setup/**'
- '.github/workflows/docker-mysql-setup.yml'
release:
types: [published, edited]

jobs:
setup:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.tag }}
publish: ${{ steps.publish.outputs.publish }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Compute Tag
id: tag
run: |
echo "GITHUB_REF: $GITHUB_REF"
SHORT_SHA=$(git rev-parse --short "$GITHUB_SHA")
echo "SHORT_SHA: $SHORT_SHA"
TAG=$(echo ${GITHUB_REF} | sed -e "s,refs/heads/.*$,head\,${SHORT_SHA},g" -e 's,refs/tags/,,g' -e 's,refs/pull/\([0-9]*\).*,pr\1,g')
echo "tag=$TAG"
echo "::set-output name=tag::$TAG"
- name: Check whether publishing enabled
id: publish
env:
ENABLE_PUBLISH: ${{ secrets.ORG_DOCKER_PASSWORD }}
run: |
echo "Enable publish: ${{ env.ENABLE_PUBLISH != '' }}"
echo "::set-output name=publish::${{ env.ENABLE_PUBLISH != '' }}"
push_to_registries:
name: Build and Push Docker Image to Docker Hub
runs-on: ubuntu-latest
needs: setup
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
# list of Docker images to use as base name for tags
images: |
acryldata/datahub-mysql-setup
# add git short SHA as Docker tag
tag-custom: ${{ needs.setup.outputs.tag }}
tag-custom-only: true
- name: Login to DockerHub
if: ${{ needs.setup.outputs.publish == 'true' }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.ORG_DOCKER_PASSWORD }}
- name: Build and Push image
uses: docker/build-push-action@v2
with:
file: ./docker/mysql-setup/Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
push: ${{ needs.setup.outputs.publish == 'true' }}
71 changes: 71 additions & 0 deletions .github/workflows/docker-postgres-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: postgres-setup docker
on:
push:
branches:
- master
paths-ignore:
- 'docs/**'
- '**.md'
pull_request:
branches:
- master
paths:
- './docker/postgres-setup/**'
- '.github/workflows/docker-postgres-setup.yml'
release:
types: [published, edited]

jobs:
setup:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.tag }}
publish: ${{ steps.publish.outputs.publish }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Compute Tag
id: tag
run: |
echo "GITHUB_REF: $GITHUB_REF"
SHORT_SHA=$(git rev-parse --short "$GITHUB_SHA")
echo "SHORT_SHA: $SHORT_SHA"
TAG=$(echo ${GITHUB_REF} | sed -e "s,refs/heads/.*$,head\,${SHORT_SHA},g" -e 's,refs/tags/,,g' -e 's,refs/pull/\([0-9]*\).*,pr\1,g')
echo "tag=$TAG"
echo "::set-output name=tag::$TAG"
- name: Check whether publishing enabled
id: publish
env:
ENABLE_PUBLISH: ${{ secrets.ORG_DOCKER_PASSWORD }}
run: |
echo "Enable publish: ${{ env.ENABLE_PUBLISH != '' }}"
echo "::set-output name=publish::${{ env.ENABLE_PUBLISH != '' }}"
push_to_registries:
name: Build and Push Docker Image to Docker Hub
runs-on: ubuntu-latest
needs: setup
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
# list of Docker images to use as base name for tags
images: |
acryldata/datahub-postgres-setup
# add git short SHA as Docker tag
tag-custom: ${{ needs.setup.outputs.tag }}
tag-custom-only: true
- name: Login to DockerHub
if: ${{ needs.setup.outputs.publish == 'true' }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.ORG_DOCKER_PASSWORD }}
- name: Build and Push image
uses: docker/build-push-action@v2
with:
file: ./docker/postgres-setup/Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
push: ${{ needs.setup.outputs.publish == 'true' }}
6 changes: 4 additions & 2 deletions docker/postgres-setup/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM jwilder/dockerize:0.6.1
FROM alpine:3

RUN apk add --no-cache postgres-client
ENV DOCKERIZE_VERSION v0.6.1
RUN apk add --no-cache postgresql-client curl tar \
&& curl -L https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz | tar -C /usr/local/bin -xzv

COPY docker/postgres-setup/init.sql /init.sql
COPY docker/postgres-setup/init.sh /init.sh
Expand Down

0 comments on commit 55c5c5c

Please sign in to comment.