Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Dockerfile
  • Loading branch information
alxlion committed Oct 7, 2023
2 parents 3d847e7 + 835495b commit d170cb8
Show file tree
Hide file tree
Showing 47 changed files with 851 additions and 598 deletions.
15 changes: 15 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%{
configs: [
%{
name: "default",
strict: false,
parse_timeout: 5000,
color: true,
checks: %{
disabled: [
{Credo.Check.Readability.ModuleDoc, []}
]
}
}
]
}
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PRESENTATION_STORAGE=local
PRESENTATION_STORAGE_DIR=/app/uploads
MAX_FILE_SIZE_MB=15

AWS_ACCESS_KEY_ID=xxx
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches: [ "main", "dev" ]
tags: ['v*']

jobs:

build:
Expand Down Expand Up @@ -41,7 +42,7 @@ jobs:
- name: Log in to registry
# This is where you will update the PAT to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Build and push Docker images
- name: Build and push Docker image
# You may pin to the exact commit or the version.
# uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
uses: docker/build-push-action@v2.10.0
Expand All @@ -52,5 +53,18 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push ARM Docker image
# You may pin to the exact commit or the version.
# uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
uses: docker/build-push-action@v2.10.0
with:
context: .
file: ./Dockerfile-arm
push: true
platforms: linux/arm64
tags: ${{ steps.meta.outputs.tags }}-arm
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max


14 changes: 11 additions & 3 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ jobs:
--health-retries 5
env:
ImageOS: ubuntu20
MIX_ENV: test
DATABASE_URL: postgresql://claper:claper@localhost:5432/claper
SECRET_KEY_BASE: QMQE4ypfy0IC1LZI/fygZNvXHPjLslnr49EE7ftcL1wgAC0MwMLdKCVJyrvXPu8z

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Elixir
uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f
with:
Expand All @@ -46,7 +52,9 @@ jobs:
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Run tests
run: mix test
- name: Check format
- name: Check Formatting
run: mix format --check-formatted
- name: Check Credo Warnings
run: mix credo diff --from-git-merge-base origin/main
- name: Run tests
run: mix test
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## v1.6.0
- Improve QR code readability
- Add ARM Docker image
- Refactor all runtime configuration
- Improve local storage with PRESENTATION_STORAGE_DIR environment variable
- Fix poll/form panel scroll on mobile
- Fix message length validation
- Fix message word break
- Fix date translations
- Minor fixes on form management

## v1.5.0

- Add a nickname feature and toggle button to avoid anonymous messages
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN apt-get update -y && apt-get install -y curl build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*

ENV NODE_VERSION 16.20.0
ENV PRESENTATION_STORAGE_DIR /app/uploads

# Install nvm with node and npm
RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash \
Expand Down Expand Up @@ -97,6 +98,7 @@ ENV HOME "/home/nobody"
RUN mkdir /home/nobody && chown nobody /home/nobody

WORKDIR "/app"
RUN mkdir /app/uploads
RUN chown nobody /app

# Only copy the final release from the build stage
Expand Down
117 changes: 117 additions & 0 deletions Dockerfile-arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of
# Alpine to avoid DNS resolution issues in production.
#
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
# https://hub.docker.com/_/ubuntu?tab=tags
#
#
# This file is based on these images:
#
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.13.2-erlang-24.2.1-debian-bullseye-20210902-slim
#
ARG BUILDER_IMAGE="hexpm/elixir-arm64:1.13.2-erlang-24.2.1-debian-bullseye-20210902-slim"
ARG RUNNER_IMAGE="debian:bullseye-20210902-slim"

FROM ${BUILDER_IMAGE} as builder

# install build dependencies
RUN apt-get update -y && apt-get install -y curl build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*

ENV NODE_VERSION 16.20.0
ENV PRESENTATION_STORAGE_DIR /app/uploads

# Install nvm with node and npm
RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash \
&& . $HOME/.nvm/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

ENV NODE_PATH $HOME/.nvm/versions/node/v$NODE_VERSION/lib/node_modules
ENV PATH $HOME/.nvm/versions/node/v$NODE_VERSION/bin:$PATH

RUN ln -sf $HOME/.nvm/versions/node/v$NODE_VERSION/bin/npm /usr/bin/npm
RUN ln -sf $HOME/.nvm/versions/node/v$NODE_VERSION/bin/node /usr/bin/node

# prepare build dir
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force

# set build ENV
ENV MIX_ENV="prod"

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile

COPY priv priv

# note: if your project uses a tool like https://purgecss.com/,
# which customizes asset compilation based on what it finds in
# your Elixir templates, you will need to move the asset compilation
# step down so that `lib` is available.
COPY assets assets

# Compile the release
COPY lib lib

RUN mix compile

# compile assets
RUN mix assets.deploy

# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/

COPY rel rel
RUN mix release

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}

RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales ghostscript \
&& apt-get install -y libreoffice --no-install-recommends && apt-get clean && rm -f /var/lib/apt/lists/*_*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV HOME "/home/nobody"

RUN mkdir /home/nobody && chown nobody /home/nobody

WORKDIR "/app"
RUN mkdir /app/uploads
RUN chown nobody /app -R

# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/prod/rel/claper ./

RUN chmod +x /app/bin/*

USER nobody

EXPOSE 4000

CMD ["sh", "-c", "/app/bin/claper eval Claper.Release.migrate && /app/bin/claper start"]

# Appended by flyctl
#ENV ECTO_IPV6 true
#ENV ERL_AFLAGS "-proto_dist inet6_tcp"
90 changes: 14 additions & 76 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,75 +24,15 @@ import topbar from "../vendor/topbar"
import Alpine from 'alpinejs'
import flatpickr from "flatpickr"
import moment from "moment-timezone"
import 'moment/locale/de'
import 'moment/locale/fr'
import QRCodeStyling from "qr-code-styling"
import { Presenter } from "./presenter"
import { Manager } from "./manager"
window.moment = moment


window.moment.locale('fr', {
months : 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'.split('_'),
monthsShort : 'janv._févr._mars_avr._mai_juin_juil._août_sept._oct._nov._déc.'.split('_'),
monthsParseExact : true,
weekdays : 'dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi'.split('_'),
weekdaysShort : 'dim._lun._mar._mer._jeu._ven._sam.'.split('_'),
weekdaysMin : 'Di_Lu_Ma_Me_Je_Ve_Sa'.split('_'),
weekdaysParseExact : true,
longDateFormat : {
LT : 'HH:mm',
LTS : 'HH:mm:ss',
L : 'DD/MM/YYYY',
LL : 'D MMMM YYYY',
LLL : 'D MMMM YYYY HH:mm',
LLLL : 'dddd D MMMM YYYY HH:mm'
},
calendar : {
sameDay : '[Aujourd’hui à] LT',
nextDay : '[Demain à] LT',
nextWeek : 'dddd [à] LT',
lastDay : '[Hier à] LT',
lastWeek : 'dddd [dernier à] LT',
sameElse : 'L'
},
relativeTime : {
future : 'dans %s',
past : 'il y a %s',
s : 'quelques secondes',
m : 'une minute',
mm : '%d minutes',
h : 'une heure',
hh : '%d heures',
d : 'un jour',
dd : '%d jours',
M : 'un mois',
MM : '%d mois',
y : 'un an',
yy : '%d ans'
},
dayOfMonthOrdinalParse : /\d{1,2}(er|e)/,
ordinal : function (number) {
return number + (number === 1 ? 'er' : 'e');
},
meridiemParse : /PD|MD/,
isPM : function (input) {
return input.charAt(0) === 'M';
},
// In case the meridiem units are not separated around 12, then implement
// this function (look at locale/id.js for an example).
// meridiemHour : function (hour, meridiem) {
// return /* 0-23 hour, given meridiem token and hour 1-12 */ ;
// },
meridiem : function (hours, minutes, isLower) {
return hours < 12 ? 'PD' : 'MD';
},
week : {
dow : 1, // Monday is the first day of the week.
doy : 4 // Used to determine first week of the year.
}
});
window.moment.locale(navigator.languages[0].split('-')[0])


window.moment.locale("en")
window.moment.locale(navigator.language.split('-')[0])
window.Alpine = Alpine
Alpine.start()

Expand Down Expand Up @@ -165,12 +105,14 @@ Hooks.PostForm = {
e.preventDefault()
submitBtn.click()
} else {
if (TA.value.length > 2) {
if (TA.value.length > 1 && TA.value.length < 256) {
submitBtn.classList.remove("opacity-50")
submitBtn.classList.add("opacity-100")
submitBtn.disabled = false
} else {
submitBtn.classList.add("opacity-50")
submitBtn.classList.remove("opacity-100")
submitBtn.disabled = true
}
}
},
Expand Down Expand Up @@ -198,12 +140,14 @@ Hooks.PostForm = {
updated() {
const submitBtn = document.getElementById("submitBtn")
const TA = document.getElementById("postFormTA")
if (TA.value.length > 2) {
if (TA.value.length > 1 && TA.value.length < 256) {
submitBtn.classList.remove("opacity-50")
submitBtn.classList.add("opacity-100")
submitBtn.disabled = false
} else {
submitBtn.classList.add("opacity-50")
submitBtn.classList.remove("opacity-100")
submitBtn.disabled = true
}
},
destroyed() {
Expand Down Expand Up @@ -392,16 +336,10 @@ Hooks.QRCode = {
},
dotsOptions: {
type: "square",
gradient: {
type: "linear",
rotation: Math.PI * 0.2,
colorStops: [{
offset: 0,
color: '#14bfdb'
}, {
offset: 1,
color: '#b80fef'
}]}
color: "#ffffff",
},
backgroundOptions: {
color: "#000000",
},
imageOptions: {
crossOrigin: "anonymous",
Expand Down
10 changes: 1 addition & 9 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ config :claper,

# Configures the endpoint
config :claper, ClaperWeb.Endpoint,
url: [host: "localhost"],
render_errors: [view: ClaperWeb.ErrorView, accepts: ~w(html json), layout: false],
pubsub_server: Claper.PubSub,
live_view: [signing_salt: "DN0vwriJgVkHG0kn3hF5JKho/DE66onv"]
Expand Down Expand Up @@ -60,14 +59,7 @@ config :phoenix, :json_library, Jason

config :porcelain, driver: Porcelain.Driver.Basic

config :ex_aws,
access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role],
secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role],
region: {:system, "AWS_REGION"},
normalize_path: false

config :claper,
max_file_size: {:system, "MAX_FILE_SIZE_MB", "15"}
config :claper, :storage_dir, System.get_env("PRESENTATION_STORAGE_DIR", "priv/static")

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
Expand Down
Loading

0 comments on commit d170cb8

Please sign in to comment.