Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate container build #16

Merged
merged 3 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI

on: [push, pull_request]

jobs:
build:
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but I think it would be helpful to split the build into separate build and deploy steps. This way, from GHA, we can gate the deploy separate from the build, and it's less "magical" looking as to what's happening.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 That sounds like a good followup since it will apply to several repos

22 changes: 11 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ FROM registry.access.redhat.com/ubi8 as base

ENV app_root=/opt/manageiq/amazon-smartstate

RUN dnf -y --disableplugin=subscription-manager module enable ruby:2.6
RUN dnf -y --disableplugin=subscription-manager module enable ruby:2.7

RUN dnf -y --disableplugin=subscription-manager install --setopt=tsflags=nodocs \
libxml2 \
libxslt \
ruby && \
dnf clean all && \
bdunne marked this conversation as resolved.
Show resolved Hide resolved
echo 'gem: --no-ri --no-rdoc --no-document' > /root/.gemrc && \
gem install bundler

######################
FROM base as gemset
Expand All @@ -16,28 +24,20 @@ RUN dnf -y --disableplugin=subscription-manager install --setopt=tsflags=nodocs
libxslt-devel \
redhat-rpm-config \
ruby-devel \
rubygem-bundler \
rubygems-devel && \
dnf clean all

COPY container-assets/* ${app_root}/

WORKDIR ${app_root}

RUN echo 'gem: --no-ri --no-rdoc --no-document' > /root/.gemrc && \
bundle config --local path gemset && \
RUN bundle config --local path gemset && \
bundle config --local bin bin && \
bundle install --jobs=8

######################
FROM base

RUN dnf -y --disableplugin=subscription-manager install --setopt=tsflags=nodocs \
libxml2 \
libxslt \
ruby \
rubygem-bundler && \
dnf clean all

ENV PATH="${app_root}/bin:${PATH}"
COPY --from=gemset ${app_root} ${app_root}
WORKDIR ${app_root}
Expand Down
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