Commit 7ce6f560 authored by Addshore's avatar Addshore 🏄
Browse files

mwdd: Add elasticsearch

parent ea659324
...@@ -44,11 +44,11 @@ test: $(GOVVV) generate ...@@ -44,11 +44,11 @@ test: $(GOVVV) generate
.PHONY: lint .PHONY: lint
lint: $(GOLANGCI_LINT) generate lint: $(GOLANGCI_LINT) generate
@$(GOLANGCI_LINT) run -E revive -E dupl -E gci -E gofmt -E gofumpt -E goimports -E whitespace @$(GOLANGCI_LINT) run -E revive -E gci -E gofmt -E gofumpt -E goimports -E whitespace
.PHONY: fix .PHONY: fix
fix: $(GOLANGCI_LINT) generate fix: $(GOLANGCI_LINT) generate
@$(GOLANGCI_LINT) run --fix -E revive -E dupl -E gci -E gofmt -E gofumpt -E goimports -E whitespace @$(GOLANGCI_LINT) run --fix -E revive -E gci -E gofmt -E gofumpt -E goimports -E whitespace
.PHONY: generate .PHONY: generate
vet: generate vet: generate
...@@ -58,3 +58,7 @@ vet: generate ...@@ -58,3 +58,7 @@ vet: generate
staticcheck: $(STATICCHECK) generate staticcheck: $(STATICCHECK) generate
$(STATICCHECK) -version $(STATICCHECK) -version
$(STATICCHECK) -- ./... $(STATICCHECK) -- ./...
.PHONY: duplicates
duplicates: $(GOLANGCI_LINT) generate
@$(GOLANGCI_LINT) run -E dupl
\ No newline at end of file
...@@ -65,14 +65,13 @@ Many other Makefile commands exist that you might find useful: ...@@ -65,14 +65,13 @@ Many other Makefile commands exist that you might find useful:
- `cmd`: Contains the Cobra commands and deals with all CLI user interaction. - `cmd`: Contains the Cobra commands and deals with all CLI user interaction.
- `internal/cmd`: General Cobra command abstractions that may be useful in multiple places. - `internal/cmd`: General Cobra command abstractions that may be useful in multiple places.
- `internal/config`: Interaction with the CLI configuration - `internal/config`: Interaction with the CLI configuration
- `internal/docker`: Logic interacting with the mediawiki-docker dev environment.
- `internal/env`: Logic interacting with a `.env` file.
- `internal/exec`: Wrapper for the main `exec` package, providing easy verbosity etc. - `internal/exec`: Wrapper for the main `exec` package, providing easy verbosity etc.
- `internal/gitlab`: Basic interaction with the Wikimedia Gitlab instance - `internal/gitlab`: Basic interaction with the Wikimedia Gitlab instance
- `internal/mediawiki`: Logic interacting with a MediaWiki installation directory on disk. - `internal/mediawiki`: Logic interacting with a MediaWiki installation directory on disk.
- `internal/mwdd`: Logic for the MediaWiki-docker-dev development environment. - `internal/mwdd`: Logic for the MediaWiki-docker-dev development environment.
- `internal/mwdd/files/embed`: Files that end up being extracted to disk for the dev environment under `~/mwcli/mwdd/default`.
- `internal/updater`: CLI tool updating. - `internal/updater`: CLI tool updating.
- `static`: Files that end up being built into the binary. - `internal/util`: A collection of quite well defined and restricted useful utility packages.
- `tests`: Integration tests that are run as part of CI. - `tests`: Integration tests that are run as part of CI.
### cmd names ### cmd names
......
/*Package cmd is used for command line.
Copyright © 2020 Addshore
This program is free software: you can elasticsearchtribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cmd
import (
"github.com/spf13/cobra"
"gitlab.wikimedia.org/releng/cli/internal/exec"
"gitlab.wikimedia.org/releng/cli/internal/mwdd"
)
var mwddElasticsearchCmd = &cobra.Command{
Use: "elasticsearch",
Short: "Elasticsearch service",
Long: `Elasticsearch service
Using this will automagically configure a elasticsearch server for MediaWiki via the CirrusSearch extension.
In order for this to do anything you will need to CirrusSearch extension installed and enabled.
$wgCirrusSearchServers = [ 'elasticsearch' ];
In order to configure a search index for a wiki, you'll need to run some maintenance scripts:
# Configure the search index and populate it with content
php extensions/CirrusSearch/maintenance/UpdateSearchIndexConfig.php
php extensions/CirrusSearch/maintenance/ForceSearchIndex.php --skipLinks --indexOnSkip
php extensions/CirrusSearch/maintenance/ForceSearchIndex.php --skipParse
# And you'll need to process the job queue any time you add/update content and want it updated in ElasticSearch
php maintenance/runJobs.php
`,
RunE: nil,
}
var mwddElasticsearchCreateCmd = &cobra.Command{
Use: "create",
Short: "Create a Elasticsearch container",
Run: func(cmd *cobra.Command, args []string) {
mwdd.DefaultForUser().EnsureReady()
mwdd.DefaultForUser().UpDetached(
[]string{"elasticsearch"},
exec.HandlerOptions{
Verbosity: Verbosity,
},
)
},
}
var mwddElasticsearchDestroyCmd = &cobra.Command{
Use: "destroy",
Short: "Destroy the Elasticsearch container and volumes",
Run: func(cmd *cobra.Command, args []string) {
mwdd.DefaultForUser().EnsureReady()
options := exec.HandlerOptions{
Verbosity: Verbosity,
}
mwdd.DefaultForUser().Rm([]string{"elasticsearch"}, options)
mwdd.DefaultForUser().RmVolumes([]string{"elasticsearch-data"}, options)
},
}
var mwddElasticsearchSuspendCmd = &cobra.Command{
Use: "suspend",
Short: "Suspend the Elasticsearch container",
Run: func(cmd *cobra.Command, args []string) {
mwdd.DefaultForUser().EnsureReady()
options := exec.HandlerOptions{
Verbosity: Verbosity,
}
mwdd.DefaultForUser().Stop([]string{"elasticsearch"}, options)
},
}
var mwddElasticsearchResumeCmd = &cobra.Command{
Use: "resume",
Short: "Resume the Elasticsearch container",
Run: func(cmd *cobra.Command, args []string) {
mwdd.DefaultForUser().EnsureReady()
options := exec.HandlerOptions{
Verbosity: Verbosity,
}
mwdd.DefaultForUser().Start([]string{"elasticsearch"}, options)
},
}
var mwddElasticsearchExecCmd = &cobra.Command{
Use: "exec [flags] [command...]",
Example: " exec bash\n exec -- bash --help\n exec --user root bash\n exec --user root -- bash --help",
Short: "Executes a command in the Elasticsearch container",
Run: func(cmd *cobra.Command, args []string) {
mwdd.DefaultForUser().EnsureReady()
mwdd.DefaultForUser().DockerExec(mwdd.DockerExecCommand{
DockerComposeService: "elasticsearch",
Command: args,
User: User,
})
},
}
func init() {
mwddCmd.AddCommand(mwddElasticsearchCmd)
mwddElasticsearchCmd.AddCommand(mwddElasticsearchCreateCmd)
mwddElasticsearchCmd.AddCommand(mwddElasticsearchDestroyCmd)
mwddElasticsearchCmd.AddCommand(mwddElasticsearchSuspendCmd)
mwddElasticsearchCmd.AddCommand(mwddElasticsearchResumeCmd)
mwddElasticsearchCmd.AddCommand(mwddElasticsearchExecCmd)
mwddElasticsearchExecCmd.Flags().StringVarP(&User, "user", "u", mwdd.UserAndGroupForDockerExecution(), "User to run as, defaults to current OS user uid:gid")
}
version: '3.7'
services:
elasticsearch:
image: docker-registry.wikimedia.org/dev/stretch-elasticsearch:0.1.0
# TODO optionally switch this automatically based on architecture?
# TODO actually build this image somewhere nicer?
# on an Apple M1 / arm64 system, you can use kostajh/wmf-elasticsearch-arm64,
# see https://gitlab.wikimedia.org/kharlan/wmf-elasticsearch-arm64/
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
environment:
- discovery.type=single-node
dns:
- 10.0.0.10
networks:
- dps
volumes:
elasticsearch-data:
driver: local
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
./mediawiki.yml ./mediawiki.yml
./files.txt ./files.txt
./wait-for-it.sh ./wait-for-it.sh
./elasticsearch.yml
./redis.yml ./redis.yml
./mysql.yml ./mysql.yml
./base.yml ./base.yml
......
...@@ -43,11 +43,13 @@ if ( defined( "MW_DB" ) ) { ...@@ -43,11 +43,13 @@ if ( defined( "MW_DB" ) ) {
} }
# Only use "advanced" services if they can be seen, and if we are not in tests # Only use "advanced" services if they can be seen, and if we are not in tests
# TODO this is confusing, tidy it up, what is it?
$mwddServices = [ $mwddServices = [
'mysql' => gethostbyname('mysql') !== 'mysql', 'mysql' => gethostbyname('mysql') !== 'mysql',
'mysql-replica' => gethostbyname('mysql-replica') !== 'mysql-replica' && !defined( 'MW_PHPUNIT_TEST' ) && !$dockerIsRunningUpdate, 'mysql-replica' => gethostbyname('mysql-replica') !== 'mysql-replica' && !defined( 'MW_PHPUNIT_TEST' ) && !$dockerIsRunningUpdate,
'redis' => gethostbyname('redis') !== 'redis' && !defined( 'MW_PHPUNIT_TEST' ), 'redis' => gethostbyname('redis') !== 'redis' && !defined( 'MW_PHPUNIT_TEST' ),
'memcached' => gethostbyname('memcached') !== 'memcached' && !defined( 'MW_PHPUNIT_TEST' ), 'memcached' => gethostbyname('memcached') !== 'memcached' && !defined( 'MW_PHPUNIT_TEST' ),
'elasticsearch' => gethostbyname('elasticsearch') !== 'elasticsearch' && !defined( 'MW_PHPUNIT_TEST' ),
'graphite' => gethostbyname('graphite') !== 'graphite' && !defined( 'MW_PHPUNIT_TEST' ), 'graphite' => gethostbyname('graphite') !== 'graphite' && !defined( 'MW_PHPUNIT_TEST' ),
]; ];
...@@ -187,6 +189,13 @@ if(gethostbyname('memcached') !== 'memcached') { ...@@ -187,6 +189,13 @@ if(gethostbyname('memcached') !== 'memcached') {
$wgMemCachedServers = [ 'memcached:11211' ]; $wgMemCachedServers = [ 'memcached:11211' ];
} }
################################
# MWDD ElasticSearch
################################
if(gethostbyname('elasticsearch') !== 'elasticsearch') {
$wgCirrusSearchServers = [ 'elasticsearch' ];
}
################################ ################################
# MWDD Graphite & Statsd # MWDD Graphite & Statsd
################################ ################################
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment