diff --git a/.woodpecker/build-docker.yml b/.woodpecker/build-docker.yml new file mode 100644 index 0000000000..0dd8208b2d --- /dev/null +++ b/.woodpecker/build-docker.yml @@ -0,0 +1,29 @@ +platform: linux/amd64 + + +variables: + - &on-release + when: + event: + - push + - tag + branch: + - docker + - &on-stable + when: + event: + - push + - tag + branch: + - stable + +pipeline: + build: + image: woodpeckerci/plugin-docker-buildx + secrets: [docker_username, docker_password] + <<: *on-release + settings: + repo: akkoma/akkoma + dockerfile: Dockerfile + platforms: linux/amd64,linux/arm64/v8 + tag: test \ No newline at end of file diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml index 16a4067fec..7400b5f0a2 100644 --- a/.woodpecker/test.yml +++ b/.woodpecker/test.yml @@ -17,6 +17,8 @@ matrix: OTP_VERSION: 25 - ELIXIR_VERSION: 1.15 OTP_VERSION: 26 + - ELIXIR_VERSION: 1.16 + OTP_VERSION: 26 variables: - &scw-secrets diff --git a/Dockerfile b/Dockerfile index aadd08f7a9..a82071830f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,35 @@ -FROM hexpm/elixir:1.15.4-erlang-26.0.2-alpine-3.18.2 +############################################## +# BUILD CONTAINER +############################################## + +FROM hexpm/elixir:1.16.0-erlang-26.2.1-alpine-3.18.4 as BUILD ENV MIX_ENV=prod + +RUN apk add git gcc g++ musl-dev make cmake file-dev exiftool ffmpeg imagemagick libmagic ncurses postgresql-client + +WORKDIR /src +ADD mix.exs mix.lock /src/ +ADD ./restarter /src/restarter/ +ADD ./priv /src/priv/ +ADD ./installation /src/installation/ +ADD ./rel /src/rel/ +ADD ./config /src/config/ +ADD ./docs /src/docs/ +ADD ./lib /src/lib/ + +RUN mix local.hex --force && \ + mix local.rebar --force + +RUN mix deps.get --only=prod + +RUN mix release --path /release + +################################################# +# RUNTIME CONTAINER +################################################# +FROM alpine:3.18 ENV ERL_EPMD_ADDRESS=127.0.0.1 - -ARG HOME=/opt/akkoma - LABEL org.opencontainers.image.title="akkoma" \ org.opencontainers.image.description="Akkoma for Docker" \ org.opencontainers.image.vendor="akkoma.dev" \ @@ -14,21 +39,16 @@ LABEL org.opencontainers.image.title="akkoma" \ org.opencontainers.image.revision=$VCS_REF \ org.opencontainers.image.created=$BUILD_DATE -RUN apk add git gcc g++ musl-dev make cmake file-dev exiftool ffmpeg imagemagick libmagic ncurses postgresql-client +RUN apk add ffmpeg imagemagick exiftool ncurses postgresql-client file-dev libmagic +COPY --from=BUILD /release /opt/akkoma/ +ADD ./docker-entrypoint.sh /opt/akkoma/ EXPOSE 4000 -ARG UID=1000 -ARG GID=1000 -ARG UNAME=akkoma - -RUN addgroup -g $GID $UNAME -RUN adduser -u $UID -G $UNAME -D -h $HOME $UNAME +VOLUME /opt/akkoma/uploads/ +VOLUME /opt/akkoma/instance/ +VOLUME /opt/akkoma/config/docker-config.exs WORKDIR /opt/akkoma -USER $UNAME -RUN mix local.hex --force &&\ - mix local.rebar --force - -CMD ["/opt/akkoma/docker-entrypoint.sh"] +CMD [ "/opt/akkoma/docker-entrypoint.sh" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 58abf189db..394593c534 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,11 +2,9 @@ version: "3.7" services: db: - image: akkoma-db:latest - build: ./docker-resources/database + image: postgres:14 shm_size: 4gb restart: unless-stopped - user: ${DOCKER_USER} environment: { # This might seem insecure but is usually not a problem. # You should leave this at the "akkoma" default. @@ -21,16 +19,17 @@ services: env_file: - .env volumes: - - type: bind - source: ./pgdata - target: /var/lib/postgresql/data + - ./pgdata:/var/lib/postgresql/data:Z + akkoma: image: akkoma:latest - build: . restart: unless-stopped env_file: - .env + environment: { + "AKKOMA_CONFIG_PATH": "/opt/akkoma/config/docker-config.exs" + } links: - db ports: [ @@ -44,7 +43,9 @@ services: "127.0.0.1:4000:4000", ] volumes: - - .:/opt/akkoma + - ./uploads:/opt/akkoma/uploads:Z + - ./instance:/opt/akkoma/instance:Z + - ./config/docker-config.exs:/opt/akkoma/config/docker-config.exs:Z # Uncomment the following if you want to use a reverse proxy #proxy: @@ -60,3 +61,6 @@ services: # - ./docker-resources/Caddyfile:/etc/caddy/Caddyfile # - ./caddy-data:/data # - ./caddy-config:/config + +volumes: + db-data: \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 778ef08e27..49319bfa93 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -8,7 +8,7 @@ while ! pg_isready -U ${DB_USER:-pleroma} -d postgres://${DB_HOST:-db}:5432/${DB done echo "-- Running migrations..." -mix ecto.migrate +/opt/akkoma/bin/pleroma_ctl migrate echo "-- Starting!" -mix phx.server +/opt/akkoma/bin/pleroma start diff --git a/docker-resources/generate-instance b/docker-resources/generate-instance new file mode 100755 index 0000000000..29de6db09d --- /dev/null +++ b/docker-resources/generate-instance @@ -0,0 +1,16 @@ +#!/bin/bash + +mkdir -p ./uploads ./instance + +podman run \ + -v ./config:/opt/akkoma/config/:Z \ + -v ./uploads:/opt/akkoma/uploads/:Z \ + -v ./instance:/opt/akkoma/instance/:Z \ + -it akkoma ./bin/pleroma_ctl instance gen \ + --dbhost db \ + --dbname akkoma \ + --dbpass akkoma \ + --dbuser akkoma \ + --static-dir /opt/akkoma/instance/ \ + --uploads-dir /opt/akkoma/uploads/ \ + --listen-ip 0.0.0.0 $@ \ No newline at end of file diff --git a/docker-resources/install-frontend b/docker-resources/install-frontend new file mode 100644 index 0000000000..ff1104988c --- /dev/null +++ b/docker-resources/install-frontend @@ -0,0 +1,3 @@ +#!/bin/bash + +podman compose run -e "PLEROMA_CTL_RPC_DISABLED=true" --rm akkoma ./bin/pleroma_ctl frontend install pleroma-fe --ref stable \ No newline at end of file diff --git a/docker-resources/manage.sh b/docker-resources/manage.sh index acb6618c3b..dd2e63902f 100755 --- a/docker-resources/manage.sh +++ b/docker-resources/manage.sh @@ -1,3 +1,3 @@ #!/bin/sh -docker compose run --rm akkoma $@ +podman compose run -e "PLEROMA_CTL_RPC_DISABLED=true" --rm akkoma ./bin/pleroma_ctl $@ diff --git a/installation/quadlet/akkoma-postgresql.container b/installation/quadlet/akkoma-postgresql.container new file mode 100644 index 0000000000..5f518ae4a3 --- /dev/null +++ b/installation/quadlet/akkoma-postgresql.container @@ -0,0 +1,23 @@ +# Put me at either: +# /usr/share/containers/systemd/akkoma-postgresql.container +# /etc/containers/systemd/akkoma-postgresql.container +# $HOME/.config/containers/systemd/akkoma-postgresql.container (for rootless podman!) + +[Unit] +Description=Akkoma's postgres database +After=local-fs.target + +[Container] +Image=docker.io/postgres:14 +PublishPort=4000 +Volume=/opt/akkoma/pgdata:/var/lib/postgresql/data:Z +AutoUpdate=registry +Environment=POSTGRES_DB=akkoma +Environment=POSTGRES_USER=akkoma +Environment=POSTGRES_PASSWORD=akkoma +ContainerName=db +Network=systemd-akkoma + +[Install] +# Start by default on boot +WantedBy=multi-user.target default.target \ No newline at end of file diff --git a/installation/quadlet/akkoma.container b/installation/quadlet/akkoma.container new file mode 100644 index 0000000000..4d45e7609b --- /dev/null +++ b/installation/quadlet/akkoma.container @@ -0,0 +1,26 @@ +# Put me at either: +# /usr/share/containers/systemd/akkoma.container +# /etc/containers/systemd/akkoma.container +# $HOME/.config/containers/systemd/akkoma.container (Recommended, for rootless podman!) + +[Unit] +Description=The main Akkoma container +After=local-fs.target akkoma-postgresql.container + +[Container] +Image=docker.io/akkoma/akkoma:test +ExposeHostPort=4000 +# Comment the next line if you intend to use containerized caddy! +PublishPort=4000:4000 +Volume=/opt/akkoma/uploads:/opt/akkoma/uploads:Z +Volume=/opt/akkoma/instance:/opt/akkoma/instance:Z +Volume=/opt/akkoma/config.exs:/opt/akkoma/config/config.exs:Z +#AutoUpdate=registry +NoNewPrivileges=true +Environment=AKKOMA_CONFIG_PATH=/opt/akkoma/config/config.exs +ContainerName=akkoma +Network=systemd-akkoma + +[Install] +# Start by default on boot +WantedBy=multi-user.target default.target \ No newline at end of file diff --git a/installation/quadlet/akkoma.network b/installation/quadlet/akkoma.network new file mode 100644 index 0000000000..b8c0f46faa --- /dev/null +++ b/installation/quadlet/akkoma.network @@ -0,0 +1,2 @@ +[Network] +Label=app=akkoma \ No newline at end of file diff --git a/installation/quadlet/caddy.container b/installation/quadlet/caddy.container new file mode 100644 index 0000000000..8727a093f9 --- /dev/null +++ b/installation/quadlet/caddy.container @@ -0,0 +1,27 @@ +# Put me at either: +# /usr/share/containers/systemd/caddy.container +# /etc/containers/systemd/caddy.container +# !!!! PLEASE NOTE !!!! +# Caddy cannot run containerised in rootless podman, since it wants access +# to privileged ports 80 and 443! +# run caddy on your host if you're rootless! + +[Unit] +Description=Akkoma's postgres database +After=local-fs.target + +[Container] +Image=docker.io/caddy:2-alpine +PublishPort=80:80 +PublishPort=443:443 +ExposeHostPort=80 +ExposeHostPort=443 +Volume=/opt/akkoma/Caddyfile:/etc/caddy/Caddyfile +Volume=/opt/akkoma/caddy-data:/data +Volume=/opt/akkoma/caddy-config:/config +AutoUpdate=registry +Network=systemd-akkoma + +[Install] +# Start by default on boot +WantedBy=multi-user.target default.target \ No newline at end of file