Skip to content

Commit

Permalink
Automate container build
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunne committed Feb 15, 2022
1 parent 35bb6e3 commit 637036f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: CI

on: [push, pull_request]

jobs:
build:
needs: ci
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up registry credentials
if: ${{ github.event_name != 'pull_request' }}
run: |
echo "REGISTRY_USERNAME=${{ secrets.REGISTRY_USERNAME }}" >> $GITHUB_ENV
echo "REGISTRY_PASSWORD=${{ secrets.REGISTRY_PASSWORD }}" >> $GITHUB_ENV
- name: Run container build script
run: bin/build_container_image
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# container-amazon-smartstate
Container for smartstate on AWS

[![CI](https://github.com/ManageIQ/container-amazon-smartstate/actions/workflows/ci.yaml/badge.svg)](https://github.com/ManageIQ/container-amazon-smartstate/actions/workflows/ci.yaml)

[![Build history for master branch](https://buildstats.info/github/chart/ManageIQ/container-amazon-smartstate?branch=master&buildCount=50&includeBuildsFromPullRequest=false&showstats=false)](https://github.com/ManageIQ/container-amazon-smartstate/actions?query=branch%3Amaster)
22 changes: 22 additions & 0 deletions bin/build_container_image
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

REGISTRY=${REGISTRY:-"docker.io"}
ORGANIZATION=${ORGANIZATION:-"manageiq"}
DEFAULT_TAG="latest"
[ "$GITHUB_EVENT_NAME" == "push" -a "$GITHUB_REF_NAME" != "master" ] && \
DEFAULT_TAG="$DEFAULT_TAG-${GITHUB_REF_NAME/\//-}"
TAG=${TAG:-"$DEFAULT_TAG"}
DEFAULT_IMAGE_NAME=$REGISTRY/$ORGANIZATION/amazon-smartstate:$TAG
IMAGE_NAME=${IMAGE_NAME:-"$DEFAULT_IMAGE_NAME"}

set -e

docker build . -t $IMAGE_NAME

[[ -z "$REGISTRY_USERNAME" ]] && exit 0

echo "$REGISTRY_PASSWORD" | docker login $REGISTRY -u $REGISTRY_USERNAME --password-stdin

docker push $IMAGE_NAME

set +e

0 comments on commit 637036f

Please sign in to comment.