Skip to content

Commit 97fcf88

Browse files
committed
prewiew
1 parent dd3d45e commit 97fcf88

File tree

5 files changed

+260
-1
lines changed

5 files changed

+260
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.env

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 dopos
3+
Copyright (c) 2019 Aleksei Kovrizhkin <lekovr+dopos@gmail.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# dcape-app-nextcloud Makefile
2+
3+
SHELL = /bin/bash
4+
CFG ?= .env
5+
6+
# Database name
7+
DB_NAME ?= nextcloud
8+
# Database user name
9+
DB_USER ?= $(DB_NAME)
10+
# Database user password
11+
DB_PASS ?= $(shell < /dev/urandom tr -dc A-Za-z0-9 | head -c14; echo)
12+
# Database dump for import on create
13+
DB_SOURCE ?=
14+
15+
# Site host
16+
APP_SITE ?= share.dev.lan
17+
18+
USER_NAME ?= nc
19+
USER_PASS ?= $(shell < /dev/urandom tr -dc A-Za-z0-9 2>/dev/null | head -c8; echo)
20+
21+
# Docker image name
22+
IMAGE ?= nextcloud
23+
# Docker image tag
24+
IMAGE_VER ?= 17.0.1RC1-apache
25+
26+
# Docker-compose project name (container name prefix)
27+
PROJECT_NAME ?= $(shell basename $$PWD)
28+
# dcape container name prefix
29+
DCAPE_PROJECT_NAME ?= dcape
30+
# dcape network attach to
31+
DCAPE_NET ?= $(DCAPE_PROJECT_NAME)_default
32+
# dcape postgresql container name
33+
DCAPE_DB ?= $(DCAPE_PROJECT_NAME)_db_1
34+
35+
# Docker-compose image tag
36+
DC_VER ?= 1.23.2
37+
38+
define CONFIG_DEF
39+
# ------------------------------------------------------------------------------
40+
# Mattermost settings
41+
42+
# Site host
43+
APP_SITE=$(APP_SITE)
44+
45+
# Admin user name
46+
USER_NAME=$(USER_NAME)
47+
# Admin user password
48+
USER_PASS=$(USER_PASS)
49+
50+
# Database name
51+
DB_NAME=$(DB_NAME)
52+
# Database user name
53+
DB_USER=$(DB_USER)
54+
# Database user password
55+
DB_PASS=$(DB_PASS)
56+
# Database dump for import on create
57+
DB_SOURCE=$(DB_SOURCE)
58+
59+
# Docker details
60+
61+
# Docker image name
62+
IMAGE=$(IMAGE)
63+
# Docker image tag
64+
IMAGE_VER=$(IMAGE_VER)
65+
66+
# Used by docker-compose
67+
# Docker-compose project name (container name prefix)
68+
PROJECT_NAME=$(PROJECT_NAME)
69+
# dcape network attach to
70+
DCAPE_NET=$(DCAPE_NET)
71+
# dcape postgresql container name
72+
DCAPE_DB=$(DCAPE_DB)
73+
74+
endef
75+
export CONFIG_DEF
76+
77+
-include $(CFG)
78+
export
79+
80+
.PHONY: all $(CFG) start start-hook stop update up reup down docker-wait db-create db-drop psql dc help
81+
82+
all: help
83+
84+
# ------------------------------------------------------------------------------
85+
# webhook commands
86+
87+
start: db-create up
88+
89+
start-hook: db-create reup
90+
91+
stop: down
92+
93+
update: reup
94+
95+
# ------------------------------------------------------------------------------
96+
# docker commands
97+
98+
## старт контейнеров
99+
up:
100+
up: CMD=up -d
101+
up: dc
102+
103+
## рестарт контейнеров
104+
reup:
105+
reup: CMD=up --force-recreate -d
106+
reup: dc
107+
108+
## остановка и удаление всех контейнеров
109+
down:
110+
down: CMD=rm -f -s
111+
down: dc
112+
113+
114+
# Wait for postgresql container start
115+
docker-wait:
116+
@echo -n "Checking PG is ready..."
117+
@until [[ `docker inspect -f "{{.State.Health.Status}}" $$DCAPE_DB` == healthy ]] ; do sleep 1 ; echo -n "." ; done
118+
@echo "Ok"
119+
120+
# ------------------------------------------------------------------------------
121+
# DB operations
122+
123+
# Database import script
124+
# DCAPE_DB_DUMP_DEST must be set in pg container
125+
126+
define IMPORT_SCRIPT
127+
[[ "$$DCAPE_DB_DUMP_DEST" ]] || { echo "DCAPE_DB_DUMP_DEST not set. Exiting" ; exit 1 ; } ; \
128+
DB_NAME="$$1" ; DB_USER="$$2" ; DB_PASS="$$3" ; DB_SOURCE="$$4" ; \
129+
dbsrc=$$DCAPE_DB_DUMP_DEST/$$DB_SOURCE.tgz ; \
130+
if [ -f $$dbsrc ] ; then \
131+
echo "Dump file $$dbsrc found, restoring database..." ; \
132+
zcat $$dbsrc | PGPASSWORD=$$DB_PASS pg_restore -h localhost -U $$DB_USER -O -Ft -d $$DB_NAME || exit 1 ; \
133+
else \
134+
echo "Dump file $$dbsrc not found" ; \
135+
exit 2 ; \
136+
fi
137+
endef
138+
export IMPORT_SCRIPT
139+
140+
# create user, db and load dump
141+
db-create: docker-wait
142+
@echo "*** $@ ***" ; \
143+
docker exec -i $$DCAPE_DB psql -U postgres -c "CREATE USER \"$$DB_USER\" WITH PASSWORD '$$DB_PASS';" || true ; \
144+
docker exec -i $$DCAPE_DB psql -U postgres -c "CREATE DATABASE \"$$DB_NAME\" OWNER \"$$DB_USER\";" || db_exists=1 ; \
145+
if [[ ! "$$db_exists" ]] ; then \
146+
if [[ "$$DB_SOURCE" ]] ; then \
147+
echo "$$IMPORT_SCRIPT" | docker exec -i $$DCAPE_DB bash -s - $$DB_NAME $$DB_USER $$DB_PASS $$DB_SOURCE \
148+
&& docker exec -i $$DCAPE_DB psql -U postgres -c "COMMENT ON DATABASE \"$$DB_NAME\" IS 'SOURCE $$DB_SOURCE';" \
149+
|| true ; \
150+
fi \
151+
fi
152+
153+
## drop database and user
154+
db-drop: docker-wait
155+
@echo "*** $@ ***"
156+
@docker exec -it $$DCAPE_DB psql -U postgres -c "DROP DATABASE \"$$DB_NAME\";" || true
157+
@docker exec -it $$DCAPE_DB psql -U postgres -c "DROP USER \"$$DB_USER\";" || true
158+
159+
psql: docker-wait
160+
@docker exec -it $$DCAPE_DB psql -U $$DB_USER -d $$DB_NAME
161+
162+
# ------------------------------------------------------------------------------
163+
164+
# $$PWD используется для того, чтобы текущий каталог был доступен в контейнере по тому же пути
165+
# и относительные тома новых контейнеров могли его использовать
166+
## run docker-compose
167+
dc: docker-compose.yml
168+
@docker run --rm \
169+
-v /var/run/docker.sock:/var/run/docker.sock \
170+
-v $$PWD:$$PWD \
171+
-w $$PWD \
172+
docker/compose:$(DC_VER) \
173+
-p $$PROJECT_NAME \
174+
$(CMD)
175+
176+
# ------------------------------------------------------------------------------
177+
178+
$(CFG):
179+
@[ -f $@ ] || { echo "$$CONFIG_DEF" > $@ ; echo "Warning: Created default $@" ; }
180+
181+
# ------------------------------------------------------------------------------
182+
183+
## List Makefile targets
184+
help:
185+
@grep -A 1 "^##" Makefile | less
186+
187+
##
188+
## Press 'q' for exit
189+
##

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
11
# dcape-app-nextcloud
22
nextcloud.com application package for dcape
3+
4+
# dcape-app-nextcloud
5+
6+
[![GitHub Release][1]][2] [![GitHub code size in bytes][3]]() [![GitHub license][4]][5]
7+
8+
[1]: https://img.shields.io/github/release/dopos/dcape-app-nextcloud.svg
9+
[2]: https://github.com/dopos/dcape-app-nextcloud/releases
10+
[3]: https://img.shields.io/github/languages/code-size/dopos/dcape-app-nextcloud.svg
11+
[4]: https://img.shields.io/github/license/dopos/dcape-app-nextcloud.svg
12+
[5]: LICENSE
13+
14+
[nextcloud](https://www.nextcloud.com/) application package for [dcape](https://github.com/dopos/dcape).
15+
16+
## Docker image used
17+
18+
* [nextcloud](https://hub.docker.com/_/nextcloud)
19+
20+
## Requirements
21+
22+
* linux 64bit (git, make, wget, gawk, openssl)
23+
* [docker](http://docker.io)
24+
* [dcape](https://github.com/dopos/dcape)
25+
* Git service ([github](https://github.com), [gitea](https://gitea.io) or [gogs](https://gogs.io))
26+
27+
## Usage
28+
29+
* Fork this repo in your Git service
30+
* Setup deploy hook
31+
* Run "Test delivery" (config sample will be created in dcape)
32+
* Edit and save config (enable deploy etc)
33+
* Run "Test delivery" again (app will be installed and started on webhook host)
34+
* Fork [dopos/dcape-dns-config](https://github/com/dopos/dcape-dns-config) and cook your zones
35+
36+
See also: [Deploy setup](https://github.com/dopos/dcape/blob/master/DEPLOY.md) (in Russian)
37+
38+
## License
39+
40+
The MIT License (MIT), see [LICENSE](LICENSE).
41+
42+
Copyright (c) 2019 Aleksei Kovrizhkin <lekovr+dopos@gmail.com>

docker-compose.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: "3.2"
2+
services:
3+
4+
app:
5+
image: ${IMAGE}:${IMAGE_VER}
6+
restart: always
7+
networks:
8+
- lan
9+
labels:
10+
- "traefik.enable=true"
11+
- "traefik.frontend.entryPoints=${ENTRY_DEFAULT}"
12+
- "traefik.frontend.redirect.entryPoints=${REDIRECT_ENTRYPOINTS}"
13+
- "traefik.frontend.rule=Host:${APP_SITE}"
14+
volumes:
15+
- /etc/timezone:/etc/timezone:ro
16+
- /etc/localtime:/etc/localtime:ro
17+
- ../../data/nextcloud:/var/www/html
18+
environment:
19+
- POSTGRES_DB=${DB_USER}
20+
- POSTGRES_USER=${DB_USER}
21+
- POSTGRES_PASSWORD=${DB_PASS}
22+
- POSTGRES_HOST=db
23+
- NEXTCLOUD_ADMIN_USER=${USER_NAME}
24+
- NEXTCLOUD_ADMIN_PASSWORD=${USER_PASS}
25+
26+
networks:
27+
lan:
28+
external:
29+
name: ${DCAPE_NET}

0 commit comments

Comments
 (0)