Skip to content

Commit

Permalink
Merge pull request #7 from ncsa/update-pg-docker
Browse files Browse the repository at this point in the history
misc updates
  • Loading branch information
robkooper authored Jul 26, 2022
2 parents 1216ad6 + 5ff2681 commit cd387d5
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 187 deletions.
127 changes: 127 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Docker

# This will run when:
# - when new code is pushed to main to push the tags
# latest as well as version tags
# - when a pull request is created and updated to make sure the
# Dockerfile is still valid.
# To be able to push to dockerhub, this execpts the following
# secrets to be set in the project:
# - DOCKERHUB_USERNAME : username that can push to the org
# - DOCKERHUB_PASSWORD : password asscoaited with the username
on:
push:
branches:
- main

pull_request:

jobs:
docker:
runs-on: ubuntu-latest
permissions:
packages: write

steps:
- uses: actions/checkout@v3

# calculate some variables that are used later
- name: variable setup
run: |
if [ "${{ github.event.release.target_commitish }}" != "" ]; then
BRANCH="${{ github.event.release.target_commitish }}"
elif [[ $GITHUB_REF =~ pull ]]; then
BRANCH="$(echo $GITHUB_REF | sed 's#refs/pull/\([0-9]*\)/merge#PR-\1#')"
else
BRANCH=${GITHUB_REF##*/}
fi
push="false"
if [ "$BRANCH" == "main" ]; then
version="$(awk '/^## / { print tolower($2) }' CHANGELOG.md | head -1)"
tags="latest"
oldversion=""
while [ "${oldversion}" != "${version}" ]; do
oldversion="${version}"
tags="${tags} ${version}"
version=${version%.*}
done
version="$(awk '/^## / { print tolower($2) }' CHANGELOG.md | head -1)"
push="true"
elif [ "$BRANCH" == "develop" ]; then
version="develop"
tags="develop"
else
version="test"
tags="${BRANCH}"
fi
push_tags=""
for tag in ${tags}; do
push_tags="${push_tags}ncsa/checks:${tag},"
push_tags="${push_tags}ghcr.io/${{ github.repository_owner }}/checks:${tag},"
done
push_tags="${push_tags%,*}"
echo "BRANCH=${BRANCH}"
echo "VERSION=${version}"
echo "TAGS=${tags}"
echo "PUSH_TAGS=${push_tags}"
echo "PUSH=${push}" >> $GITHUB_ENV
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
echo "VERSION=${version}" >> $GITHUB_ENV
echo "TAGS=${push_tags}" >> $GITHUB_ENV
# setup docker build
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Inspect Builder
run: |
echo "Name: ${{ steps.buildx.outputs.name }}"
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
echo "Status: ${{ steps.buildx.outputs.status }}"
echo "Flags: ${{ steps.buildx.outputs.flags }}"
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
# login to registries
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# build the docker images
- name: Build and push docker image
uses: docker/build-push-action@v2
with:
push: ${{ env.PUSH }}
platforms: "linux/amd64,linux/arm64"
cache-from: type=registry,ref=ncsa/checks-cache:${{ env.BRANCH }}
cache-to: type=registry,ref=ncsa/checks-cache:${{ env.BRANCH }},mode=max
tags: ${{ env.TAGS }}
build-args: |
VERSION=${{ env.VERSION }}
GITSHA1=${{ github.sha }}
# update README at DockerHub
- name: Docker Hub Description
if: github.event_name == 'push' && env.BRANCH == 'main'
uses: peter-evans/dockerhub-description@v2
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: ncsa/checks
README_FILEPATH: README.md
37 changes: 37 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Create Release

on:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: get release info
id: release_info
run: |
version="$(awk '/^## / { print tolower($2) }' CHANGELOG.md | head -1)"
changelog="$(sed -e "1,/^## ${version}/d" -e "/^## /,\$d" CHANGELOG.md)"
changelog="${changelog//'%'/'%25'}"
changelog="${changelog//$'\n'/'%0A'}"
changelog="${changelog//$'\r'/'%0D'}"
echo "::set-output name=version::$version"
echo "::set-output name=changelog::$changelog"
- name: create release
if: steps.release_info.outputs.version != 'unreleased'
uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.release_info.outputs.version }}
release_name: Release ${{ steps.release_info.outputs.version }}
body: ${{ steps.release_info.outputs.changelog }}
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.1 - 2022-07-25

### Added
- add support for standard postgresql environment variables [#2](https://github.com/ncsa/checks/issues/2)
- GitHub action to create docker file [#3](https://github.com/ncsa/checks/issues/3)

### Changed
- more verbose logging in case of check_url, thanks @khk-globus
- changed master branch to main branch.
- changed PG_URI and PG_TABLE to be PGURI and PGTABLE to be consistent with other PG variables.
- environment variable and argument in checks.json are flipped around to allow for deprecated environment variables.

## 1.0.0 - 2020-08-07

### Added
- support for RabbitMQ
- support for MongoDB
- support for URL
- support for PostgreSQL
31 changes: 18 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
# ------------------------------------------------------------
# create requirements.txt
# ------------------------------------------------------------
FROM python:3 AS pipenv
RUN pip install pipenv
COPY Pipfile* /tmp/
RUN cd /tmp && pipenv lock --requirements > requirements.txt

# ------------------------------------------------------------
# build actual container
# ------------------------------------------------------------
FROM python:3-slim
FROM python:3.8-slim

ENV TRIES=0 \
RABBITMQ_URI="" \
MONGO_URI="" \
PGURI="" \
PGHUSER="" \
PGPASSWORD="" \
PGHOST="" \
PGPORT="" \
PGDATABASE="" \
PGTABLE="" \
URL=""

ARG VERSION="unknown"
ARG GITSHA1="unknown"

LABEL org.opencontainers.image.title="Container to be used as init containers to check if the service is ready"
LABEL org.opencontainers.image.authors="Rob Kooper <kooper@illinois.edu"
LABEL org.opencontainers.image.source="https://github.com/ncsa/checks"
LABEL org.opencontainers.image.version="${VERSION}"
LABEL org.opencontainers.image.revision="${GITSHA1}"

# Install requirements
WORKDIR /usr/src
COPY --from=pipenv /tmp/requirements.txt /usr/src/
COPY requirements.txt /usr/src/
RUN pip install -r /usr/src/requirements.txt

# Copy application
Expand Down
14 changes: 0 additions & 14 deletions Pipfile

This file was deleted.

125 changes: 0 additions & 125 deletions Pipfile.lock

This file was deleted.

Loading

0 comments on commit cd387d5

Please sign in to comment.