Skip to content

Commit 8ab4a07

Browse files
authored
DOCKER: Introduce universal docker image (pglombardo#1369)
* 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
1 parent 60ed703 commit 8ab4a07

14 files changed

+431
-263
lines changed

.dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# ignore all Dockerfile copies into the containers since they're not reqiured there
22
# and speedup delevoping Dockerfiles
33
**/Dockerfile
4-
.git
4+
.git
5+
.github

.github/workflows/docker-containers.yml

+50-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,54 @@ env:
2222
DOCKER_PUSH: true
2323
jobs:
2424
build:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v3
29+
30+
- name: Set up QEMU
31+
uses: docker/setup-qemu-action@v2
32+
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v2
35+
36+
- name: Populate Docker metadata
37+
id: meta
38+
uses: docker/metadata-action@v4
39+
with:
40+
images: ${{ secrets.DOCKER_USERNAME }}/pwpush
41+
flavor: |
42+
latest=false
43+
tags: |
44+
type=match,pattern=release
45+
type=schedule,pattern=latest
46+
type=semver,pattern={{version}}
47+
type=semver,pattern={{major}}.{{minor}}
48+
type=semver,pattern={{major}}
49+
type=semver,pattern=latest
50+
51+
- name: Login to DockerHub
52+
uses: docker/login-action@v2
53+
with:
54+
username: ${{ secrets.DOCKER_USERNAME }}
55+
password: ${{ secrets.DOCKER_PASSWORD }}
56+
57+
- name: Build and push Docker image
58+
uses: docker/build-push-action@v4
59+
with:
60+
file: ./containers/docker/pwpush/Dockerfile
61+
platforms: linux/amd64,linux/arm64
62+
provenance: false
63+
push: true
64+
labels: ${{ steps.meta.outputs.labels }}
65+
tags: ${{ steps.meta.outputs.tags }}
66+
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/pwpush:buildcache
67+
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/pwpush:buildcache,mode=max,ignore-error=${{env.DOCKER_PUSH == 'false'}}
68+
69+
# 'buildObsolete'-job can be completly removed after dropping support
70+
# for old docker images.
71+
buildObsolete:
72+
needs: build
2573
runs-on: ubuntu-latest
2674
strategy:
2775
fail-fast: false
@@ -77,5 +125,5 @@ jobs:
77125
push: ${{env.DOCKER_PUSH == 'true'}}
78126
labels: ${{ steps.meta.outputs.labels }}
79127
tags: ${{ steps.meta.outputs.tags }}
80-
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/pwpush-${{ matrix.dbType }}:buildcache
81-
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/pwpush-${{ matrix.dbType }}:buildcache,mode=max,ignore-error=${{env.DOCKER_PUSH == 'false'}}
128+
build-args: |
129+
BASEIMAGE=${{ secrets.DOCKER_USERNAME }}/pwpush:${{ steps.meta.outputs.version }}
+20-70
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,22 @@
11
# pwpush-ephemeral
2-
FROM ruby:3.2-alpine AS build-env
32

4-
LABEL maintainer='[email protected]'
5-
6-
# Required packages
7-
RUN apk upgrade --no-cache \
8-
&& apk add --no-cache build-base git curl tzdata zlib-dev nodejs yarn libc6-compat sqlite-dev
9-
10-
ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}
11-
12-
RUN mkdir -p ${APP_ROOT}
13-
COPY ./ ${APP_ROOT}/
14-
15-
WORKDIR ${APP_ROOT}
16-
17-
# Setting DATABASE_URL is necessary for building.
18-
ENV DATABASE_URL=sqlite3:db/db.sqlite3
19-
20-
RUN gem install bundler
21-
22-
ENV RACK_ENV=private RAILS_ENV=private
23-
24-
RUN bundle config set without 'development production test' \
25-
&& bundle config set with 'sqlite' \
26-
&& bundle config set deployment 'true' \
27-
&& bundle install \
28-
&& yarn install
29-
30-
RUN bundle exec rails assets:precompile && bundle exec rake db:setup
31-
32-
# Removing unneccesary files/directories
33-
RUN rm -rf node_modules tmp/cache vendor/assets spec \
34-
&& rm -rf vendor/bundle/ruby/*/cache/*.gem \
35-
&& find vendor/bundle/ruby/*/gems/ -name "*.c" -delete \
36-
&& find vendor/bundle/ruby/*/gems/ -name "*.o" -delete
37-
38-
################## Build done ##################
39-
40-
FROM ruby:3.2-alpine
41-
42-
LABEL maintainer='[email protected]'
43-
44-
# install packages
45-
RUN apk upgrade --no-cache \
46-
&& apk add --no-cache tzdata bash nodejs libc6-compat
47-
48-
# Create a user and group to run the application
49-
ARG UID=1000
50-
ARG GID=1000
51-
52-
RUN addgroup -g "${GID}" pwpusher \
53-
&& adduser -D -u "${UID}" -G pwpusher pwpusher
54-
55-
56-
57-
ENV LC_CTYPE=UTF-8 LC_ALL=en_US.UTF-8
58-
ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}
59-
WORKDIR ${APP_ROOT}
60-
ENV RACK_ENV=private RAILS_ENV=private
61-
62-
RUN mkdir -p ${APP_ROOT} && chown -R pwpusher:pwpusher ${APP_ROOT}
63-
COPY --from=build-env --chown=pwpusher:pwpusher ${APP_ROOT} ${APP_ROOT}
64-
65-
ENV DATABASE_URL=sqlite3:db/db.sqlite3
66-
RUN bundle config set without 'development production test' \
67-
&& bundle config set with 'sqlite' \
68-
&& bundle config set deployment 'true'
69-
70-
USER pwpusher
71-
EXPOSE 5100
72-
ENTRYPOINT ["containers/docker/pwpush-ephemeral/entrypoint.sh"]
3+
# Using universal image as a base for old non universal image
4+
# this is for the transition phase since these old image will become obsolete
5+
ARG BASEIMAGE=pwpush:latest
6+
FROM $BASEIMAGE
7+
8+
# Insert decrecation note to inform users while spinning up containers
9+
RUN sed -i '5 a \
10+
echo " ########################################################################## "\n \
11+
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
12+
echo " ### THIS IMAGE IS DEPRECATED. SUPPORT FOR THIS IMAGE WILL BE DROPPED ### "\n \
13+
echo " ### IN THE NEAR FUTURE. PLEASE MIGRATE TO THE NEW IMAGE ### "\n \
14+
echo " ### ### "\n \
15+
echo " ### FOR MORE INFORMATION GOTO ### "\n \
16+
echo " ### https://github.com/pglombardo/PasswordPusher ### "\n \
17+
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
18+
echo " ########################################################################## "\n \
19+
' ./containers/docker/pwpush/entrypoint.sh
20+
21+
# Setting database backend
22+
ENV DATABASE_URL=sqlite3:db/db.sqlite3

containers/docker/pwpush-ephemeral/entrypoint.sh

-18
This file was deleted.
+20-68
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,22 @@
11
# pwpush-mysql
2-
FROM ruby:3.2-alpine AS build-env
32

4-
LABEL maintainer='[email protected]'
5-
6-
# Required packages
7-
RUN apk upgrade --no-cache \
8-
&& apk add --no-cache build-base git curl tzdata zlib-dev nodejs yarn libc6-compat mariadb-dev
9-
10-
ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}
11-
12-
RUN mkdir -p ${APP_ROOT}
13-
COPY ./ ${APP_ROOT}/
14-
15-
WORKDIR ${APP_ROOT}
16-
17-
# Setting DATABASE_URL is necessary for building.
18-
ENV DATABASE_URL=mysql2://passwordpusher_user:passwordpusher_passwd@mysql:3306/passwordpusher_db
19-
20-
RUN gem install bundler
21-
22-
ENV RACK_ENV=production RAILS_ENV=production RAILS_SERVE_STATIC_FILES=true
23-
24-
RUN bundle config set without 'development private test' \
25-
&& bundle config set with 'mysql' \
26-
&& bundle config set deployment 'true' \
27-
&& bundle install \
28-
&& yarn install
29-
30-
RUN bundle exec rails assets:precompile
31-
32-
# Removing unneccesary files/directories
33-
RUN rm -rf node_modules tmp/cache vendor/assets spec \
34-
&& rm -rf vendor/bundle/ruby/*/cache/*.gem \
35-
&& find vendor/bundle/ruby/*/gems/ -name "*.c" -delete \
36-
&& find vendor/bundle/ruby/*/gems/ -name "*.o" -delete
37-
38-
################## Build done ##################
39-
40-
FROM ruby:3.2-alpine
41-
42-
LABEL maintainer='[email protected]'
43-
44-
# install packages
45-
RUN apk upgrade --no-cache \
46-
&& apk add --no-cache tzdata bash nodejs libc6-compat mariadb-connector-c
47-
48-
# Create a user and group to run the application
49-
ARG UID=1000
50-
ARG GID=1000
51-
52-
RUN addgroup -g "${GID}" pwpusher \
53-
&& adduser -D -u "${UID}" -G pwpusher pwpusher
54-
55-
ENV LC_CTYPE=UTF-8 LC_ALL=en_US.UTF-8
56-
ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}
57-
WORKDIR ${APP_ROOT}
58-
ENV RACK_ENV=production RAILS_ENV=production RAILS_SERVE_STATIC_FILES=true
59-
60-
RUN mkdir -p ${APP_ROOT} && chown -R pwpusher:pwpusher ${APP_ROOT}
61-
COPY --from=build-env --chown=pwpusher:pwpusher ${APP_ROOT} ${APP_ROOT}
62-
63-
ENV DATABASE_URL=mysql2://passwordpusher_user:passwordpusher_passwd@mysql:3306/passwordpusher_db
64-
RUN bundle config set without 'development private test' \
65-
&& bundle config set with 'mysql' \
66-
&& bundle config set deployment 'true'
67-
68-
USER pwpusher
69-
EXPOSE 5100
70-
ENTRYPOINT ["containers/docker/pwpush-mysql/entrypoint.sh"]
3+
# Using universal image as a base for old non universal image
4+
# this is for the transition phase since these old image will become obsolete
5+
ARG BASEIMAGE=pwpush:latest
6+
FROM $BASEIMAGE
7+
8+
# Insert decrecation note to inform users while spinning up containers
9+
RUN sed -i '5 a \
10+
echo " ########################################################################## "\n \
11+
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
12+
echo " ### THIS IMAGE IS DEPRECATED. SUPPORT FOR THIS IMAGE WILL BE DROPPED ### "\n \
13+
echo " ### IN THE NEAR FUTURE. PLEASE MIGRATE TO THE NEW IMAGE ### "\n \
14+
echo " ### ### "\n \
15+
echo " ### FOR MORE INFORMATION GOTO ### "\n \
16+
echo " ### https://github.com/pglombardo/PasswordPusher ### "\n \
17+
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
18+
echo " ########################################################################## "\n \
19+
' ./containers/docker/pwpush/entrypoint.sh
20+
21+
# Setting database backend
22+
ENV DATABASE_URL=mysql2://passwordpusher_user:passwordpusher_passwd@mysql:3306/passwordpusher_db

containers/docker/pwpush-mysql/entrypoint.sh

-18
This file was deleted.
+20-68
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,22 @@
11
# pwpush-postgres
2-
FROM ruby:3.2-alpine AS build-env
32

4-
LABEL maintainer='[email protected]'
5-
6-
# Required packages
7-
RUN apk upgrade --no-cache \
8-
&& apk add --no-cache build-base git curl tzdata zlib-dev nodejs yarn libc6-compat libpq-dev
9-
10-
ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}
11-
12-
RUN mkdir -p ${APP_ROOT}
13-
COPY ./ ${APP_ROOT}/
14-
15-
WORKDIR ${APP_ROOT}
16-
17-
# Setting DATABASE_URL is necessary for building.
18-
ENV DATABASE_URL=postgres://passwordpusher_user:passwordpusher_passwd@postgres:5432/passwordpusher_db
19-
20-
RUN gem install bundler
21-
22-
ENV RACK_ENV=production RAILS_ENV=production RAILS_SERVE_STATIC_FILES=true
23-
24-
RUN bundle config set without 'development private test' \
25-
&& bundle config set with 'postgres' \
26-
&& bundle config set deployment 'true' \
27-
&& bundle install \
28-
&& yarn install
29-
30-
RUN bundle exec rails assets:precompile
31-
32-
# Removing unneccesary files/directories
33-
RUN rm -rf node_modules tmp/cache vendor/assets spec \
34-
&& rm -rf vendor/bundle/ruby/*/cache/*.gem \
35-
&& find vendor/bundle/ruby/*/gems/ -name "*.c" -delete \
36-
&& find vendor/bundle/ruby/*/gems/ -name "*.o" -delete
37-
38-
################## Build done ##################
39-
40-
FROM ruby:3.2-alpine
41-
42-
LABEL maintainer='[email protected]'
43-
44-
# install packages
45-
RUN apk upgrade --no-cache \
46-
&& apk add --no-cache tzdata bash nodejs libc6-compat libpq
47-
48-
# Create a user and group to run the application
49-
ARG UID=1000
50-
ARG GID=1000
51-
52-
RUN addgroup -g "${GID}" pwpusher \
53-
&& adduser -D -u "${UID}" -G pwpusher pwpusher
54-
55-
ENV LC_CTYPE=UTF-8 LC_ALL=en_US.UTF-8
56-
ENV APP_ROOT=/opt/PasswordPusher PATH=${APP_ROOT}:${PATH} HOME=${APP_ROOT}
57-
WORKDIR ${APP_ROOT}
58-
ENV RACK_ENV=production RAILS_ENV=production RAILS_SERVE_STATIC_FILES=true
59-
60-
RUN mkdir -p ${APP_ROOT} && chown -R pwpusher:pwpusher ${APP_ROOT}
61-
COPY --from=build-env --chown=pwpusher:pwpusher ${APP_ROOT} ${APP_ROOT}
62-
63-
ENV DATABASE_URL=postgres://passwordpusher_user:passwordpusher_passwd@postgres:5432/passwordpusher_db
64-
RUN bundle config set without 'development private test' \
65-
&& bundle config set with 'postgres' \
66-
&& bundle config set deployment 'true'
67-
68-
USER pwpusher
69-
EXPOSE 5100
70-
ENTRYPOINT ["containers/docker/pwpush-postgres/entrypoint.sh"]
3+
# Using universal image as a base for old non universal image
4+
# this is for the transition phase since these old image will become obsolete
5+
ARG BASEIMAGE=pwpush:latest
6+
FROM $BASEIMAGE
7+
8+
# Insert decrecation note to inform users while spinning up containers
9+
RUN sed -i '5 a \
10+
echo " ########################################################################## "\n \
11+
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
12+
echo " ### THIS IMAGE IS DEPRECATED. SUPPORT FOR THIS IMAGE WILL BE DROPPED ### "\n \
13+
echo " ### IN THE NEAR FUTURE. PLEASE MIGRATE TO THE NEW IMAGE ### "\n \
14+
echo " ### ### "\n \
15+
echo " ### FOR MORE INFORMATION GOTO ### "\n \
16+
echo " ### https://github.com/pglombardo/PasswordPusher ### "\n \
17+
echo " ### !!DEPRECATION NOTIFICATION!! ### "\n \
18+
echo " ########################################################################## "\n \
19+
' ./containers/docker/pwpush/entrypoint.sh
20+
21+
# Setting database backend
22+
ENV DATABASE_URL=postgres://passwordpusher_user:passwordpusher_passwd@postgres:5432/passwordpusher_db

0 commit comments

Comments
 (0)