Nomad : Multiple Task

395 views
Skip to first unread message

rethkevi...@fligno.com

unread,
Aug 24, 2020, 11:05:30 PM8/24/20
to Nomad
Hi, Need some help, how can I connect two task in 1 nomad job?
I want to create an Artifactory service and it needs the postgres and artifactory image, based on the documentation for docker compose the artifactory images "depends_on" postgres image. How can i do this as nomad job?

Marek Sirový

unread,
Aug 25, 2020, 12:01:49 AM8/25/20
to rethkevi...@fligno.com, Nomad
Hi,

I’ve found only this implementation of dependencies in nomad 

Does this help?


On Tue, 25 Aug 2020 at 05:05, rethkevi...@fligno.com <rethkevi...@fligno.com> wrote:
Hi, Need some help, how can I connect two task in 1 nomad job?
I want to create an Artifactory service and it needs the postgres and artifactory image, based on the documentation for docker compose the artifactory images "depends_on" postgres image. How can i do this as nomad job?





Disclaimer: This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. https://fligno.com








--


In the coming weeks, inbound messages to this group will be disabled, and it will be used for outbound announcements only. To prepare for this switch, please direct questions and conversations to our primary medium to communicate with practitioners: https://discuss.hashicorp.com/c/nomad/28. We look forward to collaborating with you there!


 


GitHub Issues: https://github.com/hashicorp/nomad/issues


 


This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines Behavior in violation of those guidelines may result in your removal from this mailing list.


---


You received this message because you are subscribed to the Google Groups "Nomad" group.


To unsubscribe from this group and stop receiving emails from it, send an email to nomad-tool+...@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msgid/nomad-tool/194c9088-0a62-46cb-be98-b0cbda29f4c7n%40googlegroups.com.


--
Marek Sirovy

a.ahmad...@gmail.com

unread,
Aug 25, 2020, 12:23:40 AM8/25/20
to Nomad
Hi, I do this with some tricks such as template and consul service names.

could you send your docker-compose file?
Message has been deleted

rethkevi...@fligno.com

unread,
Aug 25, 2020, 12:31:26 AM8/25/20
to Nomad
this is the docker-compose file

version: '3'
services:
  postgres:
    image: ${DOCKER_REGISTRY}/postgres:9.6.11
    container_name: postgresql
    environment:
     - POSTGRES_DB=artifactory
     - POSTGRES_USER=artifactory
     - POSTGRES_PASSWORD=password
    ports:
      - 5432:5432
    volumes:
     - ${ROOT_DATA_DIR}/var/data/postgres/data:/var/lib/postgresql/data
     - /etc/localtime:/etc/localtime:ro
    restart: always
    logging:
      driver: json-file
      options:
        max-size: "50m"
        max-file: "10"
    ulimits:
      nproc: 65535
      nofile:
        soft: 32000
        hard: 40000
    healthcheck:
      test: ["CMD", "pg_isready"]
      interval: 1s
      timeout: 3s
      retries: 30
  artifactory:
    image: ${DOCKER_REGISTRY}/jfrog/artifactory-oss:${ARTIFACTORY_VERSION}
    container_name: artifactory
    volumes:
     - ${ROOT_DATA_DIR}/var:/var/opt/jfrog/artifactory
     - /etc/localtime:/etc/localtime:ro
    restart: always
    depends_on:
    - postgres
    ulimits:
      nproc: 65535
      nofile:
        soft: 32000
        hard: 40000
    environment:
      - JF_ROUTER_ENTRYPOINTS_EXTERNALPORT=${JF_ROUTER_ENTRYPOINTS_EXTERNALPORT}
    ports:
      - ${JF_ROUTER_ENTRYPOINTS_EXTERNALPORT}:${JF_ROUTER_ENTRYPOINTS_EXTERNALPORT} # for router communication
      - 8081:8081 # for artifactory communication
    logging:
      driver: json-file
      options:
        max-size: "50m"
        max-file: "10"

a.ahmad...@gmail.com

unread,
Aug 25, 2020, 12:49:36 AM8/25/20
to Nomad
Do you have consul cluster with your nomad?

Is "$ARTIFACTORY_HOME/etc/db.properties " the config file setting postgresql address? I need content of the file. Please send me the config file.

The trick is that you should create config file inside your job file and use consul template to connecting to the depend service.

rethkevi...@fligno.com

unread,
Aug 25, 2020, 1:01:06 AM8/25/20
to Nomad
yes I have a consul cluster.

I dont have this  $ARTIFACTORY_HOME/etc/db.properties , I just use the docker-compose sample code on artifactory. 

https://github.com/jfrog/artifactory-docker-examples/blob/master/docker-compose/artifactory/artifactory-oss-postgresql.yml  

rethkevi...@fligno.com

unread,
Aug 25, 2020, 1:43:13 AM8/25/20
to Nomad
still newbie on this stuff

a.ahmad...@gmail.com

unread,
Aug 25, 2020, 4:10:58 AM8/25/20
to Nomad
I tried to write a job with minimum requirements. You may need to change it but the most important point is about {{ range service "postgres" }}{{ .Address }}:5432{{ end }} .
I try to connect artifact to postgresql using config file and postgresql service.

I hope this could help you. I write every depends services with this trick. :)

Azam Ahmadloo

I tried to upload the job file but there was some errors, so send you the file contents.

************************************************************************************************************************************************************************************
************************************************************************************************************************************************************************************



job "artifact" {
datacenters = [ "dc1"]
type = "service"
priority = 100

group "artifactory" {
restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}
ephemeral_disk {
migrate = false
size = "1024" #MB
sticky = true
}

task "pgsql" {
driver = "docker"
config {
image = "postgres:9.6.11"
port_map {
pgsql-port = 5432
}
env {
POSTGRES_DB=artifactory
POSTGRES_USER=artifactory
POSTGRES_PASSWORD=password
}
ulimit {
# ensure elastic search can create enough open file handles
nofile = "65536"

# ensure elastic search can create enough threads
nproc = "65535"
}
volumes = [
"/data/postgres/data:/var/lib/postgresql/data",
"/etc/localtime:/etc/localtime:ro"
]
}
resources {
cpu = 100
memory = 512
network {
mbits = 10
port "postgresConn" { static = 5432 }
}
}
service {
name = "postgres"
port = "postgresConn"
check {
name = "postgresql_check"
type = "tcp"
interval = "60s"
timeout = "5s"
}
}
}

task "artifact" {
driver = "docker"
config {
image = "your-artifact-image"
port_map {
external-port = 2222
arti-port = 8081
}
volumes = [
"local/db-config.conf:$ARTIFACTORY_HOME/etc/db.properties ",
"/data/artifact/data:/var/opt/jfrog/artifactory",
"/etc/localtime:/etc/localtime"
]
env {
JF_ROUTER_ENTRYPOINTS_EXTERNALPORT=JF_ROUTER_ENTRYPOINTS_EXTERNALPORT
}
}
template {
destination = "local/db-config.conf"
data = <<EOH
type=postgresql
driver=org.postgresql.Driver
url=jdbc:postgresql://{{ range service "postgres" }}{{ .Address }}:5432{{ end }}/artifactory?ssl=true&sslfactory=org.postgresql.ssl.jdbc4.LibPQFactory&sslmode=verify-full
EOH
}
resources {
cpu = 100
memory = 512
network {
mbits = 10
port "external" { static = 2222 }
port "arti" { static = 8081 }
}
}
service {
name = "artifact"
port = "arti"
check {
name = "artifact_check"
type = "tcp"
interval = "60s"
timeout = "5s"
}
}
}
}
}
Message has been deleted

a.ahmad...@gmail.com

unread,
Aug 25, 2020, 4:20:53 AM8/25/20
to Nomad
 
I found config file from this link but you could run the service with docker-compose and find config file then use it in your job or dome jobs let you to config service with environment variables.
Anyway, you should find a way to connect jobs to each other with variables.
 
 
https://www.jfrog.com/confluence/display/RTF6X/PostgreSQL
 
 
Azam Ahmadloo

Alexandra Freeman

unread,
Aug 27, 2020, 9:22:19 PM8/27/20
to Nomad

Hello and thank you for your email!

On June 3, 2019 HashiCorp launched Discuss, a forum to facilitate dialogue within the HashiCorp community. This format allows answers to be more readily searched and indexed, making it easier to find answers to existing questions and to share knowledge with each other.

The HashiCorp team will be shifting to interact with practitioners on the forum, and we will be phasing out the Google Groups; on August 31 at 5pm EDT, inbound messages to this group will be disabled, and it will be used for outbound announcements only.

To prepare for this switch, please direct questions and conversations to the Nomad discussion forum. We look forward to collaborating with you there!
Reply all
Reply to author
Forward
0 new messages