Skip to content

Commit d1927fc

Browse files
authored
Merge pull request #37 from qdm12/docker
Docker
2 parents 599657c + 0e7ddcb commit d1927fc

10 files changed

+628
-0
lines changed

.dockerignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.git
2+
.github
3+
tests
4+
.dockerignore
5+
.editorconfig
6+
.env.example
7+
.env.testing
8+
.gitattributes
9+
.gitignore
10+
.styleci.yml
11+
.travis.yml
12+
changelog.md
13+
Dockerfile
14+
LICENSE
15+
README.md
16+
webpack.mix.js

.github/workflows/ci.yml

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: CI
2+
on:
3+
push:
4+
paths:
5+
- .github/workflows/ci.yml
6+
- app/**
7+
- bootstrap/**
8+
- config/**
9+
- database/**
10+
- docker/**
11+
- public/**
12+
- resources/**
13+
- routes/**
14+
- storage/**
15+
- tests/**
16+
- .dockerignore
17+
- .env.travis
18+
- artisan
19+
- composer.json
20+
- composer.lock
21+
- Dockerfile
22+
- phpunit.xml
23+
- server.php
24+
pull_request:
25+
paths:
26+
- .github/workflows/ci.yml
27+
- app/**
28+
- bootstrap/**
29+
- config/**
30+
- database/**
31+
- docker/**
32+
- public/**
33+
- resources/**
34+
- routes/**
35+
- storage/**
36+
- tests/**
37+
- .dockerignore
38+
- .env.travis
39+
- artisan
40+
- composer.json
41+
- composer.lock
42+
- Dockerfile
43+
- phpunit.xml
44+
- server.php
45+
46+
jobs:
47+
verify:
48+
runs-on: ubuntu-latest
49+
env:
50+
DOCKER_BUILDKIT: "1"
51+
steps:
52+
- uses: actions/[email protected]
53+
54+
- name: Build test image
55+
run: docker build --target test -t test-container .
56+
57+
- name: Run tests in test container
58+
run: |
59+
touch coverage.txt
60+
docker run --rm \
61+
test-container
62+
63+
- name: Build final image
64+
run: docker build .
65+
66+
publish:
67+
needs: [verify]
68+
if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name == github.repository
69+
runs-on: ubuntu-latest
70+
steps:
71+
- uses: actions/[email protected]
72+
with:
73+
ref: ${{github.event.pull_request.head.ref}}
74+
repository: ${{github.event.pull_request.head.repo.full_name}}
75+
76+
- uses: docker/setup-qemu-action@v1
77+
- uses: docker/setup-buildx-action@v1
78+
79+
- uses: docker/login-action@v1
80+
with:
81+
username: 2fauth
82+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
83+
84+
- name: Set variables
85+
id: vars
86+
env:
87+
EVENT_NAME: ${{ github.event_name }}
88+
run: |
89+
BRANCH=${GITHUB_REF#refs/heads/}
90+
TAG=${GITHUB_REF#refs/tags/}
91+
echo ::set-output name=commit::$(git rev-parse --short HEAD)
92+
echo ::set-output name=created::$(date -u +%Y-%m-%dT%H:%M:%SZ)
93+
if [ "$TAG" != "$GITHUB_REF" ]; then
94+
echo ::set-output name=version::$TAG
95+
echo ::set-output name=platforms::linux/amd64,linux/386,linux/arm64,linux/arm/v6,linux/arm/v7
96+
elif [ "$BRANCH" = "master" ]; then
97+
echo ::set-output name=version::latest
98+
echo ::set-output name=platforms::linux/amd64,linux/386,linux/arm64,linux/arm/v6,linux/arm/v7
99+
else
100+
echo ::set-output name=version::$BRANCH
101+
echo ::set-output name=platforms::linux/amd64
102+
fi
103+
104+
- name: Build and push final image
105+
uses: docker/[email protected]
106+
with:
107+
platforms: ${{ steps.vars.outputs.platforms }}
108+
build-args: |
109+
CREATED=${{ steps.vars.outputs.created }}
110+
COMMIT=${{ steps.vars.outputs.commit }}
111+
VERSION=${{ steps.vars.outputs.version }}
112+
tags: |
113+
2fauth/2fauth:${{ steps.vars.outputs.version }}
114+
push: true
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Docker Hub description
2+
on:
3+
push:
4+
branches: [master]
5+
paths:
6+
- docker/README.md
7+
- .github/workflows/dockerhub-readme.yml
8+
jobs:
9+
dockerHubDescription:
10+
if: github.event.pull_request.head.repo.full_name == github.repository
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/[email protected]
15+
- name: Docker Hub Description
16+
uses: peter-evans/[email protected]
17+
with:
18+
username: 2fauth
19+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
20+
repository: 2fauth/2fauth
21+
short-description: A web app to manage your Two-Factor Authentication (2FA) accounts and generate their security codes
22+
readme-filepath: docker/README.md

Dockerfile

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
ARG BUILDPLATFORM=linux/amd64
2+
ARG TARGETPLATFORM
3+
ARG ALPINE_VERSION=3.14
4+
ARG PHP_VERSION=7.3-alpine${ALPINE_VERSION}
5+
ARG COMPOSER_VERSION=2.1
6+
ARG SUPERVISORD_VERSION=v0.7.3
7+
8+
FROM --platform=${BUILDPLATFORM} composer:${COMPOSER_VERSION} AS build-composer
9+
FROM composer:${COMPOSER_VERSION} AS composer
10+
FROM qmcgaw/binpot:supervisord-${SUPERVISORD_VERSION} AS supervisord
11+
12+
FROM --platform=${BUILDPLATFORM} php:${PHP_VERSION} AS vendor
13+
COPY --from=build-composer --chown=${UID}:${GID} /usr/bin/composer /usr/bin/composer
14+
RUN apk add --no-cache unzip
15+
WORKDIR /srv
16+
COPY artisan composer.json composer.lock ./
17+
COPY database ./database
18+
RUN composer install --prefer-dist --no-scripts --no-dev --no-autoloader
19+
RUN composer dump-autoload --no-scripts --no-dev --optimize
20+
21+
FROM --platform=${BUILDPLATFORM} vendor AS test
22+
COPY . .
23+
RUN mv .env.travis .env
24+
RUN composer install
25+
RUN php artisan key:generate
26+
ENTRYPOINT [ "/srv/vendor/bin/phpunit" ]
27+
28+
FROM alpine:${ALPINE_VERSION}
29+
30+
ARG UID=1000
31+
ARG GID=1000
32+
33+
# Composer 2
34+
COPY --from=composer --chown=${UID}:${GID} /usr/bin/composer /usr/bin/composer
35+
# Supervisord from https://github.com/ochinchina/supervisord
36+
COPY --from=supervisord --chown=${UID}:${GID} /bin /usr/local/bin/supervisord
37+
38+
# Install PHP and PHP system dependencies
39+
RUN apk add --update --no-cache \
40+
# PHP
41+
php7 \
42+
# Composer dependencies
43+
php7-phar \
44+
# PHP SQLite driver
45+
php7-pdo_sqlite php7-sqlite3 \
46+
# PHP extensions
47+
php7-xml php7-gd php7-mbstring \
48+
# Runtime dependencies
49+
php7-session php7-json php7-openssl \
50+
# Nginx and PHP FPM to serve over HTTP
51+
php7-fpm nginx \
52+
&& \
53+
# Clean up
54+
rm /etc/nginx/nginx.conf && \
55+
# Fix ownership to ${UID}:${GID}
56+
chown -R ${UID}:${GID} /var/lib/nginx/
57+
58+
# PHP FPM configuration
59+
# Change username and ownership in php-fpm pool config
60+
RUN sed -i '/user = nobody/d' /etc/php7/php-fpm.d/www.conf && \
61+
sed -i '/group = nobody/d' /etc/php7/php-fpm.d/www.conf && \
62+
sed -i '/listen.owner/d' /etc/php7/php-fpm.d/www.conf && \
63+
sed -i '/listen.group/d' /etc/php7/php-fpm.d/www.conf
64+
# Pre-create files with the correct permissions
65+
RUN mkdir /run/php && \
66+
chown ${UID}:${GID} /run/php /var/log/php7 && \
67+
chmod 700 /run/php /var/log/php7
68+
69+
# Nginx configuration
70+
EXPOSE 8000/tcp
71+
RUN touch /run/nginx/nginx.pid /var/lib/nginx/logs/error.log && \
72+
chown ${UID}:${GID} /run/nginx/nginx.pid /var/lib/nginx/logs/error.log
73+
COPY --chown=${UID}:${GID} docker/nginx.conf /etc/nginx/nginx.conf
74+
RUN nginx -t
75+
76+
# Supervisord configuration
77+
COPY --chown=${UID}:${GID} docker/supervisord.conf /etc/supervisor/supervisord.conf
78+
79+
# Create end user directory
80+
RUN mkdir -p /2fauth && \
81+
chown -R ${UID}:${GID} /2fauth && \
82+
chmod 700 /2fauth
83+
84+
# Create /srv internal directory
85+
WORKDIR /srv
86+
RUN chown -R ${UID}:${GID} /srv && \
87+
chmod 700 /srv
88+
89+
# Run without root
90+
USER ${UID}:${GID}
91+
92+
# Dependencies
93+
COPY --from=vendor --chown=${UID}:${GID} /srv/vendor /srv/vendor
94+
95+
# Copy the rest of the code
96+
COPY --chown=${UID}:${GID} . .
97+
# RUN composer dump-autoload --no-scripts --no-dev --optimize
98+
99+
# Entrypoint
100+
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
101+
COPY --chown=${UID}:${GID} docker/entrypoint.sh /usr/local/bin/entrypoint.sh
102+
RUN chmod 500 /usr/local/bin/entrypoint.sh
103+
104+
ENV \
105+
# You can change the name of the app
106+
APP_NAME=2FAuth \
107+
# You can leave this on "local". If you change it to production most console commands will ask for extra confirmation.
108+
# Never set it to "testing".
109+
APP_ENV=local \
110+
# Set to true if you want to see debug information in error screens.
111+
APP_DEBUG=false \
112+
# This should be your email address
113+
114+
# The encryption key for our database and sessions. Keep this very secure.
115+
# If you generate a new one all existing data must be considered LOST.
116+
# Change it to a string of exactly 32 chars or use command `php artisan key:generate` to generate it
117+
APP_KEY=SomeRandomStringOf32CharsExactly \
118+
# This variable must match your installation's external address but keep in mind that
119+
# it's only used on the command line as a fallback value.
120+
APP_URL=http://localhost \
121+
# Turn this to true if you want your app to react like a demo.
122+
# The Demo mode reset the app content every hours and set a generic demo user.
123+
IS_DEMO_APP=false \
124+
# The log channel defines where your log entries go to.
125+
# 'daily' is the default logging mode giving you 5 daily rotated log files in /storage/logs/.
126+
# Several other options exist. You can use 'single' for one big fat error log (not recommended).
127+
# Also available are 'syslog', 'errorlog' and 'stdout' which will log to the system itself.
128+
LOG_CHANNEL=daily \
129+
# Log level. You can set this from least severe to most severe:
130+
# debug, info, notice, warning, error, critical, alert, emergency
131+
# If you set it to debug your logs will grow large, and fast. If you set it to emergency probably
132+
# nothing will get logged, ever.
133+
APP_LOG_LEVEL=notice \
134+
# Database config & credentials
135+
# DB_CONNECTION can only be sqlite
136+
DB_CONNECTION=sqlite \
137+
DB_DATABASE="/srv/database/database.sqlite" \
138+
# If you're looking for performance improvements, you could install memcached.
139+
CACHE_DRIVER=file \
140+
SESSION_DRIVER=file \
141+
# Mail settings
142+
# Refer your email provider documentation to configure your mail settings
143+
# Set a value for every available setting to avoid issue
144+
MAIL_DRIVER=log \
145+
MAIL_HOST=smtp.mailtrap.io \
146+
MAIL_PORT=2525 \
147+
148+
MAIL_USERNAME=null \
149+
MAIL_PASSWORD=null \
150+
MAIL_ENCRYPTION=null \
151+
MAIL_FROM_NAME=null \
152+
MAIL_FROM_ADDRESS=null \
153+
# Leave the following configuration vars as is.
154+
# Unless you like to tinker and know what you're doing.
155+
BROADCAST_DRIVER=log \
156+
QUEUE_DRIVER=sync \
157+
SESSION_LIFETIME=12 \
158+
REDIS_HOST=127.0.0.1 \
159+
REDIS_PASSWORD=null \
160+
REDIS_PORT=6379 \
161+
PUSHER_APP_ID= \
162+
PUSHER_APP_KEY= \
163+
PUSHER_APP_SECRET= \
164+
PUSHER_APP_CLUSTER=mt1 \
165+
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" \
166+
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" \
167+
MIX_ENV=local
168+
169+
ARG VERSION=unknown
170+
ARG CREATED="an unknown date"
171+
ARG COMMIT=unknown
172+
ENV \
173+
VERSION=${VERSION} \
174+
CREATED=${CREATED} \
175+
COMMIT=${COMMIT}
176+
LABEL \
177+
org.opencontainers.image.authors="https://github.com/Bubka" \
178+
org.opencontainers.image.version=$VERSION \
179+
org.opencontainers.image.created=$CREATED \
180+
org.opencontainers.image.revision=$COMMIT \
181+
org.opencontainers.image.url="https://github.com/Bubka/2FAuth" \
182+
org.opencontainers.image.documentation="https://hub.docker.com/r/2fauth/2fauth" \
183+
org.opencontainers.image.source="https://github.com/Bubka/2FAuth" \
184+
org.opencontainers.image.title="2fauth" \
185+
org.opencontainers.image.description="A web app to manage your Two-Factor Authentication (2FA) accounts and generate their security codes"

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 2FAuth
22

33
![https://travis-ci.com/github/Bubka/2FAuth](https://img.shields.io/travis/com/bubka/2fauth?style=flat-square)
4+
[![Docker build status](https://github.com/Bubka/2fauth/actions/workflows/ci.yml/badge.svg)](https://github.com/Bubka/2fauth/actions/workflows/ci.yml)
45
![https://codecov.io/gh/Bubka/2FAuth](https://img.shields.io/codecov/c/github/Bubka/2FAuth?style=flat-square)
56
![https://github.com/Bubka/2FAuth/blob/master/LICENSE](https://img.shields.io/github/license/Bubka/2FAuth.svg?style=flat-square)
67

@@ -10,6 +11,8 @@ A web app to manage your Two-Factor Authentication (2FA) accounts and generate t
1011

1112
[**2FAuth Demo**](https://demo.2fauth.app/)
1213

14+
[**Use it with Docker**](docker)
15+
1316
Credentials (login - password) : *[email protected]* - *demo*
1417

1518
## Purpose

0 commit comments

Comments
 (0)