Skip to content

Commit efe71cd

Browse files
authored
docker: refactor (#1438)
* docker: refactor * github/docker: bump actions and adjust smp ports
1 parent ae41717 commit efe71cd

File tree

10 files changed

+287
-65
lines changed

10 files changed

+287
-65
lines changed

.github/workflows/docker-image.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ jobs:
1414
matrix:
1515
include:
1616
- app: smp-server
17-
app_port: 5223
17+
app_port: "443 5223"
1818
- app: xftp-server
19-
app_port: 443
19+
app_port: 443
2020
steps:
2121
- name: Clone project
22-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
2323

2424
- name: Log in to Docker Hub
25-
uses: docker/login-action@v2
25+
uses: docker/login-action@v3
2626
with:
2727
username: ${{ secrets.DOCKERHUB_USERNAME }}
2828
password: ${{ secrets.DOCKERHUB_PASSWORD }}
2929

3030
- name: Extract metadata for Docker image
3131
id: meta
32-
uses: docker/metadata-action@v4
32+
uses: docker/metadata-action@v5
3333
with:
3434
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.app }}
3535
flavor: |
@@ -40,7 +40,7 @@ jobs:
4040
type=semver,pattern=v{{major}}
4141
4242
- name: Build and push Docker image
43-
uses: docker/build-push-action@v4
43+
uses: docker/build-push-action@v6
4444
with:
4545
push: true
4646
build-args: |

Dockerfile

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
ARG TAG=22.04
1+
# syntax=docker/dockerfile:1.7.0-labs
2+
ARG TAG=24.04
23

34
FROM ubuntu:${TAG} AS build
45

56
### Build stage
67

78
# Install curl and git and simplexmq dependencies
8-
RUN apt-get update && apt-get install -y curl git build-essential libgmp3-dev zlib1g-dev llvm-12 llvm-12-dev libnuma-dev libssl-dev
9+
RUN apt-get update && apt-get install -y curl git build-essential libgmp3-dev zlib1g-dev llvm-18 llvm-18-dev libnuma-dev libssl-dev
910

1011
# Specify bootstrap Haskell versions
1112
ENV BOOTSTRAP_HASKELL_GHC_VERSION=9.6.3
12-
ENV BOOTSTRAP_HASKELL_CABAL_VERSION=3.10.1.0
13+
ENV BOOTSTRAP_HASKELL_CABAL_VERSION=3.12.1.0
14+
15+
# Do not install Stack
16+
ENV BOOTSTRAP_HASKELL_INSTALL_NO_STACK=true
17+
ENV BOOTSTRAP_HASKELL_INSTALL_NO_STACK_HOOK=true
1318

1419
# Install ghcup
1520
RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 sh
@@ -21,26 +26,42 @@ ENV PATH="/root/.cabal/bin:/root/.ghcup/bin:$PATH"
2126
RUN ghcup set ghc "${BOOTSTRAP_HASKELL_GHC_VERSION}" && \
2227
ghcup set cabal "${BOOTSTRAP_HASKELL_CABAL_VERSION}"
2328

24-
COPY . /project
29+
# Copy only the source code
30+
COPY apps /project/apps/
31+
COPY cbits /project/cbits/
32+
COPY src /project/src/
33+
34+
COPY cabal.project Setup.hs simplexmq.cabal LICENSE /project
35+
2536
WORKDIR /project
2637

38+
# Debug
39+
#ARG CACHEBUST=1
40+
41+
#ADD --chmod=755 https://github.com/MShekow/directory-checksum/releases/download/v1.4.6/directory-checksum_1.4.6_linux_amd64 /usr/local/bin/directory-checksum
42+
#RUN directory-checksum --max-depth 2 .
43+
44+
# Set build arguments and check if they exist
2745
ARG APP
28-
ARG APP_PORT
29-
RUN if [ -z "$APP" ] || [ -z "$APP_PORT" ]; then printf "Please spcify \$APP and \$APP_PORT build-arg.\n"; exit 1; fi
46+
RUN if [ -z "$APP" ]; then printf "Please spcify \$APP build-arg.\n"; exit 1; fi
3047

3148
# Compile app
3249
RUN cabal update
3350
RUN cabal build exe:$APP
3451

52+
# Copy scripts
53+
COPY scripts /project/scripts/
54+
3555
# Create new path containing all files needed
3656
RUN mkdir /final
3757
WORKDIR /final
3858

3959
# Strip the binary from debug symbols to reduce size
40-
RUN bin=$(find /project/dist-newstyle -name "$APP" -type f -executable) && \
60+
RUN bin="$(find /project/dist-newstyle -name "$APP" -type f -executable)" && \
4161
mv "$bin" ./ && \
4262
strip ./"$APP" &&\
43-
mv /project/scripts/docker/entrypoint-"$APP" ./entrypoint
63+
mv /project/scripts/docker/entrypoint-"$APP" ./entrypoint &&\
64+
mv /project/scripts/main/simplex-servers-stopscript ./simplex-servers-stopscript
4465

4566
### Final stage
4667
FROM ubuntu:${TAG}
@@ -53,6 +74,8 @@ COPY --from=build /final /usr/local/bin/
5374

5475
# Open app listening port
5576
ARG APP_PORT
77+
RUN if [ -z "$APP_PORT" ]; then printf "Please spcify \$APP_PORT build-arg.\n"; exit 1; fi
78+
5679
EXPOSE $APP_PORT
5780

5881
# simplexmq requires using SIGINT to correctly preserve undelivered messages and restore them on restart
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: SimpleX Chat - smp-server
2+
3+
services:
4+
oneshot:
5+
image: ubuntu:latest
6+
environment:
7+
CADDYCONF: |
8+
${CADDY_OPTS:-}
9+
10+
http://{$$ADDR} {
11+
redir https://{$$ADDR}{uri} permanent
12+
}
13+
14+
{$$ADDR}:8443 {
15+
tls {
16+
key_type rsa4096
17+
}
18+
}
19+
command: sh -c 'if [ ! -f /etc/caddy/Caddyfile ]; then printf "$${CADDYCONF}" > /etc/caddy/Caddyfile; fi'
20+
volumes:
21+
- ./caddy_conf:/etc/caddy
22+
23+
caddy:
24+
image: caddy:latest
25+
depends_on:
26+
oneshot:
27+
condition: service_completed_successfully
28+
cap_add:
29+
- NET_ADMIN
30+
environment:
31+
ADDR: ${ADDR?"Please specify the domain."}
32+
volumes:
33+
- ./caddy_conf:/etc/caddy
34+
- caddy_data:/data
35+
- caddy_config:/config
36+
ports:
37+
- 80:80
38+
restart: unless-stopped
39+
healthcheck:
40+
test: "test -d /data/caddy/certificates/${CERT_PATH:-acme-v02.api.letsencrypt.org-directory}/${ADDR} || exit 1"
41+
interval: 1s
42+
retries: 60
43+
44+
smp-server:
45+
image: ${SIMPLEX_IMAGE:-simplexchat/smp-server:latest}
46+
depends_on:
47+
caddy:
48+
condition: service_healthy
49+
environment:
50+
ADDR: ${ADDR?"Please specify the domain."}
51+
PASS: ${PASS:-}
52+
volumes:
53+
- ./smp_configs:/etc/opt/simplex
54+
- ./smp_state:/var/opt/simplex
55+
- type: volume
56+
source: caddy_data
57+
target: /certificates
58+
volume:
59+
subpath: "caddy/certificates/${CERT_PATH:-acme-v02.api.letsencrypt.org-directory}/${ADDR}"
60+
ports:
61+
- 443:443
62+
- 5223:5223
63+
restart: unless-stopped
64+
65+
volumes:
66+
caddy_data:
67+
caddy_config:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: SimpleX Chat - smp-server
2+
3+
services:
4+
smp-server:
5+
image: ${SIMPLEX_IMAGE:-simplexchat/smp-server:latest}
6+
environment:
7+
WEB_MANUAL: ${WEB_MANUAL:-1}
8+
ADDR: ${ADDR?"Please specify the domain."}
9+
PASS: ${PASS:-}
10+
volumes:
11+
- ./smp_configs:/etc/opt/simplex
12+
- ./smp_state:/var/opt/simplex
13+
ports:
14+
- 5223:5223
15+
restart: unless-stopped
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Mandatory
2+
ADDR=your_ip_or_addr
3+
4+
# Optional
5+
#PASS='123123'
6+
#WEB_MANUAL=1
7+
8+
# Debug
9+
#SIMPLEX_SMP_IMAGE=smp-server-dev
10+
#CERT_PATH=acme-staging-v02.api.letsencrypt.org-directory
11+
#CADDY_OPTS='{\n acme_ca https://acme-staging-v02.api.letsencrypt.org/directory\n}'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Mandatory
2+
ADDR=your_ip_or_addr
3+
QUOTA=120gb
4+
5+
# Optional
6+
#PASS='123123'
7+
8+
# Debug
9+
#SIMPLEX_XFTP_IMAGE=xftp-server-dev
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: SimpleX Chat - xftp-server
2+
3+
services:
4+
xftp-server:
5+
image: ${SIMPLEX_XFTP_IMAGE:-simplexchat/xftp-server:latest}
6+
environment:
7+
ADDR: ${ADDR?"Please specify the domain."}
8+
QUOTA: ${QUOTA?"Please specify disk quota."}
9+
PASS: ${PASS:-}
10+
volumes:
11+
- ./xftp_configs:/etc/opt/simplex-xftp
12+
- ./xftp_state:/var/opt/simplex-xftp
13+
- ./xftp_files:/srv/xftp
14+
ports:
15+
- 443:443
16+
restart: unless-stopped

scripts/docker/entrypoint-smp-server

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,87 @@
11
#!/usr/bin/env sh
2+
set -e
3+
24
confd='/etc/opt/simplex'
3-
logd='/var/opt/simplex/'
5+
cert_path='/certificates'
46

57
# Check if server has been initialized
68
if [ ! -f "${confd}/smp-server.ini" ]; then
79
# If not, determine ip or domain
810
case "${ADDR}" in
9-
'') printf 'Please specify $ADDR environment variable.\n'; exit 1 ;;
11+
'')
12+
printf 'Please specify $ADDR environment variable.\n'
13+
exit 1
14+
;;
15+
16+
# Determine domain or IPv6
1017
*[a-zA-Z]*)
1118
case "${ADDR}" in
12-
*:*) set -- --ip "${ADDR}" ;;
13-
*) set -- -n "${ADDR}" ;;
19+
# IPv6
20+
*:*)
21+
set -- --ip "${ADDR}"
22+
;;
23+
24+
# Domain
25+
*)
26+
case "${ADDR}" in
27+
# It's in domain format
28+
*.*)
29+
# Determine the base domain
30+
ADDR_BASE="$(printf '%s' "$ADDR" | awk -F. '{print $(NF-1)"."$NF}')"
31+
set -- --fqdn "${ADDR}" --own-domains="${ADDR_BASE}"
32+
;;
33+
34+
# Incorrect domain
35+
*)
36+
printf 'Incorrect $ADDR environment variable. Please specify the correct one in format: smp1.example.org / example.org \n'
37+
exit 1
38+
;;
39+
esac
1440
esac
1541
;;
16-
*) set -- --ip "${ADDR}" ;;
42+
43+
# Assume everything else is IPv4
44+
*)
45+
set -- --ip "${ADDR}" ;;
1746
esac
1847

1948
# Optionally, set password
2049
case "${PASS}" in
21-
'') set -- "$@" --no-password ;;
22-
*) set -- "$@" --password "${PASS}" ;;
50+
# Empty value = no password
51+
'')
52+
set -- "$@" --no-password
53+
;;
54+
55+
# Assume that everything else is a password
56+
*)
57+
set -- "$@" --password "${PASS}"
58+
;;
2359
esac
2460

2561
# And init certificates and configs
26-
smp-server init -y -l "$@"
62+
smp-server init --yes \
63+
--store-log \
64+
--daily-stats \
65+
--source-code \
66+
"$@" > /dev/null 2>&1
67+
68+
# Fix path to certificates
69+
if [ -n "${WEB_MANUAL}" ]; then
70+
sed -i -e 's|^[^#]*https: |#&|' \
71+
-e 's|^[^#]*cert: |#&|' \
72+
-e 's|^[^#]*key: |#&|' \
73+
-e 's|^port:.*|port: 5223|' \
74+
"${confd}/smp-server.ini"
75+
else
76+
sed -i -e "s|cert: /etc/opt/simplex/web.crt|cert: $cert_path/$ADDR.crt|" \
77+
-e "s|key: /etc/opt/simplex/web.key|key: $cert_path/$ADDR.key|" \
78+
"${confd}/smp-server.ini"
79+
fi
2780
fi
2881

2982
# Backup store log just in case
30-
#
31-
# Uses the UTC (universal) time zone and this
32-
# format: YYYY-mm-dd'T'HH:MM:SS
33-
# year, month, day, letter T, hour, minute, second
34-
#
35-
# This is the ISO 8601 format without the time zone at the end.
36-
#
37-
_file="${logd}/smp-server-store.log"
38-
if [ -f "${_file}" ]; then
39-
_backup_extension="$(date -u '+%Y-%m-%dT%H:%M:%S')"
40-
cp -v -p "${_file}" "${_file}.${_backup_extension:-date-failed}"
41-
unset -v _backup_extension
42-
fi
43-
unset -v _file
83+
DOCKER=true /usr/local/bin/simplex-servers-stopscript smp-server
4484

4585
# Finally, run smp-sever. Notice that "exec" here is important:
4686
# smp-server replaces our helper script, so that it can catch INT signal
4787
exec smp-server start +RTS -N -RTS
48-

0 commit comments

Comments
 (0)