Skip to content

Commit

Permalink
DOCKER: Introduce universal docker image (pglombardo#1369)
Browse files Browse the repository at this point in the history
* added dockerfile for unified docker image
and example docker compose files

* let old obsolete docker image use new unified
image as base image and add deprecation note

* reconfigured github build action to
respect docker container image changes

* ignore '.github' directory for docker builds
  • Loading branch information
sirux88 authored Oct 6, 2023
1 parent 60ed703 commit 8ab4a07
Show file tree
Hide file tree
Showing 14 changed files with 431 additions and 263 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ignore all Dockerfile copies into the containers since they're not reqiured there
# and speedup delevoping Dockerfiles
**/Dockerfile
.git
.git
.github
52 changes: 50 additions & 2 deletions .github/workflows/docker-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,54 @@ env:
DOCKER_PUSH: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

- name: Populate Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ secrets.DOCKER_USERNAME }}/pwpush
flavor: |
latest=false
tags: |
type=match,pattern=release
type=schedule,pattern=latest
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=semver,pattern=latest
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
file: ./containers/docker/pwpush/Dockerfile
platforms: linux/amd64,linux/arm64
provenance: false
push: true
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/pwpush:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/pwpush:buildcache,mode=max,ignore-error=${{env.DOCKER_PUSH == 'false'}}

# 'buildObsolete'-job can be completly removed after dropping support
# for old docker images.
buildObsolete:
needs: build
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -77,5 +125,5 @@ jobs:
push: ${{env.DOCKER_PUSH == 'true'}}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/pwpush-${{ matrix.dbType }}:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/pwpush-${{ matrix.dbType }}:buildcache,mode=max,ignore-error=${{env.DOCKER_PUSH == 'false'}}
build-args: |
BASEIMAGE=${{ secrets.DOCKER_USERNAME }}/pwpush:${{ steps.meta.outputs.version }}
90 changes: 20 additions & 70 deletions containers/docker/pwpush-ephemeral/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,72 +1,22 @@
# pwpush-ephemeral
FROM ruby:3.2-alpine AS build-env

LABEL maintainer='[email protected]'

# Required packages
RUN apk upgrade --no-cache \
&& apk add --no-cache build-base git curl tzdata zlib-dev nodejs yarn libc6-compat sqlite-dev

ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}

RUN mkdir -p ${APP_ROOT}
COPY ./ ${APP_ROOT}/

WORKDIR ${APP_ROOT}

# Setting DATABASE_URL is necessary for building.
ENV DATABASE_URL=sqlite3:db/db.sqlite3

RUN gem install bundler

ENV RACK_ENV=private RAILS_ENV=private

RUN bundle config set without 'development production test' \
&& bundle config set with 'sqlite' \
&& bundle config set deployment 'true' \
&& bundle install \
&& yarn install

RUN bundle exec rails assets:precompile && bundle exec rake db:setup

# Removing unneccesary files/directories
RUN rm -rf node_modules tmp/cache vendor/assets spec \
&& rm -rf vendor/bundle/ruby/*/cache/*.gem \
&& find vendor/bundle/ruby/*/gems/ -name "*.c" -delete \
&& find vendor/bundle/ruby/*/gems/ -name "*.o" -delete

################## Build done ##################

FROM ruby:3.2-alpine

LABEL maintainer='[email protected]'

# install packages
RUN apk upgrade --no-cache \
&& apk add --no-cache tzdata bash nodejs libc6-compat

# Create a user and group to run the application
ARG UID=1000
ARG GID=1000

RUN addgroup -g "${GID}" pwpusher \
&& adduser -D -u "${UID}" -G pwpusher pwpusher



ENV LC_CTYPE=UTF-8 LC_ALL=en_US.UTF-8
ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}
WORKDIR ${APP_ROOT}
ENV RACK_ENV=private RAILS_ENV=private

RUN mkdir -p ${APP_ROOT} && chown -R pwpusher:pwpusher ${APP_ROOT}
COPY --from=build-env --chown=pwpusher:pwpusher ${APP_ROOT} ${APP_ROOT}

ENV DATABASE_URL=sqlite3:db/db.sqlite3
RUN bundle config set without 'development production test' \
&& bundle config set with 'sqlite' \
&& bundle config set deployment 'true'

USER pwpusher
EXPOSE 5100
ENTRYPOINT ["containers/docker/pwpush-ephemeral/entrypoint.sh"]
# Using universal image as a base for old non universal image
# this is for the transition phase since these old image will become obsolete
ARG BASEIMAGE=pwpush:latest
FROM $BASEIMAGE

# Insert decrecation note to inform users while spinning up containers
RUN sed -i '5 a \
echo " ########################################################################## "\n \
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
echo " ### THIS IMAGE IS DEPRECATED. SUPPORT FOR THIS IMAGE WILL BE DROPPED ### "\n \
echo " ### IN THE NEAR FUTURE. PLEASE MIGRATE TO THE NEW IMAGE ### "\n \
echo " ### ### "\n \
echo " ### FOR MORE INFORMATION GOTO ### "\n \
echo " ### https://github.com/pglombardo/PasswordPusher ### "\n \
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
echo " ########################################################################## "\n \
' ./containers/docker/pwpush/entrypoint.sh

# Setting database backend
ENV DATABASE_URL=sqlite3:db/db.sqlite3
18 changes: 0 additions & 18 deletions containers/docker/pwpush-ephemeral/entrypoint.sh

This file was deleted.

88 changes: 20 additions & 68 deletions containers/docker/pwpush-mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,70 +1,22 @@
# pwpush-mysql
FROM ruby:3.2-alpine AS build-env

LABEL maintainer='[email protected]'

# Required packages
RUN apk upgrade --no-cache \
&& apk add --no-cache build-base git curl tzdata zlib-dev nodejs yarn libc6-compat mariadb-dev

ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}

RUN mkdir -p ${APP_ROOT}
COPY ./ ${APP_ROOT}/

WORKDIR ${APP_ROOT}

# Setting DATABASE_URL is necessary for building.
ENV DATABASE_URL=mysql2://passwordpusher_user:passwordpusher_passwd@mysql:3306/passwordpusher_db

RUN gem install bundler

ENV RACK_ENV=production RAILS_ENV=production RAILS_SERVE_STATIC_FILES=true

RUN bundle config set without 'development private test' \
&& bundle config set with 'mysql' \
&& bundle config set deployment 'true' \
&& bundle install \
&& yarn install

RUN bundle exec rails assets:precompile

# Removing unneccesary files/directories
RUN rm -rf node_modules tmp/cache vendor/assets spec \
&& rm -rf vendor/bundle/ruby/*/cache/*.gem \
&& find vendor/bundle/ruby/*/gems/ -name "*.c" -delete \
&& find vendor/bundle/ruby/*/gems/ -name "*.o" -delete

################## Build done ##################

FROM ruby:3.2-alpine

LABEL maintainer='[email protected]'

# install packages
RUN apk upgrade --no-cache \
&& apk add --no-cache tzdata bash nodejs libc6-compat mariadb-connector-c

# Create a user and group to run the application
ARG UID=1000
ARG GID=1000

RUN addgroup -g "${GID}" pwpusher \
&& adduser -D -u "${UID}" -G pwpusher pwpusher

ENV LC_CTYPE=UTF-8 LC_ALL=en_US.UTF-8
ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}
WORKDIR ${APP_ROOT}
ENV RACK_ENV=production RAILS_ENV=production RAILS_SERVE_STATIC_FILES=true

RUN mkdir -p ${APP_ROOT} && chown -R pwpusher:pwpusher ${APP_ROOT}
COPY --from=build-env --chown=pwpusher:pwpusher ${APP_ROOT} ${APP_ROOT}

ENV DATABASE_URL=mysql2://passwordpusher_user:passwordpusher_passwd@mysql:3306/passwordpusher_db
RUN bundle config set without 'development private test' \
&& bundle config set with 'mysql' \
&& bundle config set deployment 'true'

USER pwpusher
EXPOSE 5100
ENTRYPOINT ["containers/docker/pwpush-mysql/entrypoint.sh"]
# Using universal image as a base for old non universal image
# this is for the transition phase since these old image will become obsolete
ARG BASEIMAGE=pwpush:latest
FROM $BASEIMAGE

# Insert decrecation note to inform users while spinning up containers
RUN sed -i '5 a \
echo " ########################################################################## "\n \
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
echo " ### THIS IMAGE IS DEPRECATED. SUPPORT FOR THIS IMAGE WILL BE DROPPED ### "\n \
echo " ### IN THE NEAR FUTURE. PLEASE MIGRATE TO THE NEW IMAGE ### "\n \
echo " ### ### "\n \
echo " ### FOR MORE INFORMATION GOTO ### "\n \
echo " ### https://github.com/pglombardo/PasswordPusher ### "\n \
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
echo " ########################################################################## "\n \
' ./containers/docker/pwpush/entrypoint.sh

# Setting database backend
ENV DATABASE_URL=mysql2://passwordpusher_user:passwordpusher_passwd@mysql:3306/passwordpusher_db
18 changes: 0 additions & 18 deletions containers/docker/pwpush-mysql/entrypoint.sh

This file was deleted.

88 changes: 20 additions & 68 deletions containers/docker/pwpush-postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,70 +1,22 @@
# pwpush-postgres
FROM ruby:3.2-alpine AS build-env

LABEL maintainer='[email protected]'

# Required packages
RUN apk upgrade --no-cache \
&& apk add --no-cache build-base git curl tzdata zlib-dev nodejs yarn libc6-compat libpq-dev

ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}

RUN mkdir -p ${APP_ROOT}
COPY ./ ${APP_ROOT}/

WORKDIR ${APP_ROOT}

# Setting DATABASE_URL is necessary for building.
ENV DATABASE_URL=postgres://passwordpusher_user:passwordpusher_passwd@postgres:5432/passwordpusher_db

RUN gem install bundler

ENV RACK_ENV=production RAILS_ENV=production RAILS_SERVE_STATIC_FILES=true

RUN bundle config set without 'development private test' \
&& bundle config set with 'postgres' \
&& bundle config set deployment 'true' \
&& bundle install \
&& yarn install

RUN bundle exec rails assets:precompile

# Removing unneccesary files/directories
RUN rm -rf node_modules tmp/cache vendor/assets spec \
&& rm -rf vendor/bundle/ruby/*/cache/*.gem \
&& find vendor/bundle/ruby/*/gems/ -name "*.c" -delete \
&& find vendor/bundle/ruby/*/gems/ -name "*.o" -delete

################## Build done ##################

FROM ruby:3.2-alpine

LABEL maintainer='[email protected]'

# install packages
RUN apk upgrade --no-cache \
&& apk add --no-cache tzdata bash nodejs libc6-compat libpq

# Create a user and group to run the application
ARG UID=1000
ARG GID=1000

RUN addgroup -g "${GID}" pwpusher \
&& adduser -D -u "${UID}" -G pwpusher pwpusher

ENV LC_CTYPE=UTF-8 LC_ALL=en_US.UTF-8
ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}
WORKDIR ${APP_ROOT}
ENV RACK_ENV=production RAILS_ENV=production RAILS_SERVE_STATIC_FILES=true

RUN mkdir -p ${APP_ROOT} && chown -R pwpusher:pwpusher ${APP_ROOT}
COPY --from=build-env --chown=pwpusher:pwpusher ${APP_ROOT} ${APP_ROOT}

ENV DATABASE_URL=postgres://passwordpusher_user:passwordpusher_passwd@postgres:5432/passwordpusher_db
RUN bundle config set without 'development private test' \
&& bundle config set with 'postgres' \
&& bundle config set deployment 'true'

USER pwpusher
EXPOSE 5100
ENTRYPOINT ["containers/docker/pwpush-postgres/entrypoint.sh"]
# Using universal image as a base for old non universal image
# this is for the transition phase since these old image will become obsolete
ARG BASEIMAGE=pwpush:latest
FROM $BASEIMAGE

# Insert decrecation note to inform users while spinning up containers
RUN sed -i '5 a \
echo " ########################################################################## "\n \
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
echo " ### THIS IMAGE IS DEPRECATED. SUPPORT FOR THIS IMAGE WILL BE DROPPED ### "\n \
echo " ### IN THE NEAR FUTURE. PLEASE MIGRATE TO THE NEW IMAGE ### "\n \
echo " ### ### "\n \
echo " ### FOR MORE INFORMATION GOTO ### "\n \
echo " ### https://github.com/pglombardo/PasswordPusher ### "\n \
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
echo " ########################################################################## "\n \
' ./containers/docker/pwpush/entrypoint.sh

# Setting database backend
ENV DATABASE_URL=postgres://passwordpusher_user:passwordpusher_passwd@postgres:5432/passwordpusher_db
Loading

0 comments on commit 8ab4a07

Please sign in to comment.