github.com/fabianvf/ocp-release-operator-sdk@v0.0.0-20190426141702-57620ee2f090/internal/pkg/scaffold/ansible/dockerfilehybrid.go (about) 1 // Copyright 2019 The Operator-SDK Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package ansible 16 17 import ( 18 "path/filepath" 19 20 "github.com/operator-framework/operator-sdk/internal/pkg/scaffold" 21 "github.com/operator-framework/operator-sdk/internal/pkg/scaffold/input" 22 ) 23 24 //DockerfileHybrid - Dockerfile for a hybrid operator 25 type DockerfileHybrid struct { 26 input.Input 27 28 // Playbook - if true, include a COPY statement for playbook.yml 29 Playbook bool 30 31 // Roles - if true, include a COPY statement for the roles directory 32 Roles bool 33 34 // Watches - if true, include a COPY statement for watches.yaml 35 Watches bool 36 } 37 38 // GetInput - gets the input 39 func (d *DockerfileHybrid) GetInput() (input.Input, error) { 40 if d.Path == "" { 41 d.Path = filepath.Join(scaffold.BuildDir, scaffold.DockerfileFile) 42 } 43 d.TemplateBody = dockerFileHybridAnsibleTmpl 44 return d.Input, nil 45 } 46 47 const dockerFileHybridAnsibleTmpl = `FROM ansible/ansible-runner 48 49 RUN yum remove -y ansible python-idna 50 RUN yum install -y inotify-tools && yum clean all 51 RUN pip uninstall ansible-runner -y 52 53 RUN pip install --upgrade setuptools 54 RUN pip install ansible ansible-runner openshift kubernetes ansible-runner-http idna==2.7 55 56 RUN mkdir -p /etc/ansible \ 57 && echo "localhost ansible_connection=local" > /etc/ansible/hosts \ 58 && echo '[defaults]' > /etc/ansible/ansible.cfg \ 59 && echo 'roles_path = /opt/ansible/roles' >> /etc/ansible/ansible.cfg \ 60 && echo 'library = /usr/share/ansible/openshift' >> /etc/ansible/ansible.cfg 61 62 ENV OPERATOR=/usr/local/bin/ansible-operator \ 63 USER_UID=1001 \ 64 USER_NAME=ansible-operator\ 65 HOME=/opt/ansible 66 67 {{- if .Watches }} 68 COPY watches.yaml ${HOME}/watches.yaml{{ end }} 69 70 # install operator binary 71 COPY build/_output/bin/{{.ProjectName}} ${OPERATOR} 72 # install k8s_status Ansible Module 73 COPY library/k8s_status.py /usr/share/ansible/openshift/ 74 75 COPY bin /usr/local/bin 76 RUN /usr/local/bin/user_setup 77 78 {{- if .Roles }} 79 COPY roles/ ${HOME}/roles/{{ end }} 80 {{- if .Playbook }} 81 COPY playbook.yml ${HOME}/playbook.yml{{ end }} 82 83 ENTRYPOINT ["/usr/local/bin/entrypoint"] 84 85 USER ${USER_UID} 86 `