# schema version determines supported fields schema_version: 20180708 # name matches directory name containing the code name: ldap-hotwrap version: 0.0.1 # 2min for function execution timeout: 120 |
FROM docker.io/oraclelinux:7 # Install hotwrap binary in the container COPY --from=fnproject/hotwrap:latest /hotwrap /hotwrap # Function runs by fn user (uid 1000), it has to be created # RUN commit changes into new image during build time RUN groupadd --gid 1000 fn && \ adduser --uid 1000 --gid fn -d /home/fn fn && \ mkdir -p /home/fn/.ssh && chown -R fn:fn /home/fn/.ssh && chmod 700 /home/fn/.ssh COPY id_rsa-opc /home/fn/.ssh/id_rsa-opc RUN chown fn:fn /home/fn/.ssh/id_rsa-opc && chmod 400 /home/fn/.ssh/id_rsa-opc COPY ldap_config.sh /ldap_config.sh # hard-coded OCI compute name ENV COMPUTE <oci-compute-name> RUN echo $COMPUTE > /compute.txt # CMD defines argument for ENTRYPOINT CMD "/bin/scp -i /home/fn/.ssh/id_rsa-opc -o \"StrictHostKeyChecking no\" /ldap_config.sh opc@`echo $COMPUTE`:/tmp && /bin/ssh -i /home/fn/.ssh/id_rsa-opc -o \"StrictHostKeyChecking no\" opc@`echo $COMPUTE` \"sudo /tmp/ldap_config.sh\" " # Defines what to executes during container runtime ENTRYPOINT ["/hotwrap"] |
fn -v build |
Syntax: fn -v deploy --app <application-name> Ex: fn -v deploy --app ldap-app |
oci fn function invoke \ --function-id ocid1.fnfunc.oc1.iad.aaaa-shortened-wdka \ --file "-" --body "" |
Syntax: fn -v invoke <application-name> <function-name> Ex: fn -v invoke ldap-app ldap-hotwrap |
FROM oraclelinux:8 RUN groupadd --gid 1000 fn && \ adduser --uid 1000 --gid fn -d /home/fn fn && \ mkdir -p /home/fn/.ssh && chown -R fn:fn /home/fn/.ssh && chmod 700 /home/fn/.ssh WORKDIR /function ADD requirements.txt /function/ ADD id_rsa-opc /home/fn/.ssh RUN yum -y install python36 && pip3 install --no-cache --no-cache-dir -r requirements.txt && \ rm -fr ~/.cache/pip /tmp* requirements.txt func.yaml Dockerfile .venv && \ chown fn:fn /home/fn/.ssh/id_rsa-opc && chmod 400 /home/fn/.ssh/id_rsa-opc ADD . /function/ RUN rm -fr /function/.pip_cache ENTRYPOINT ["/usr/local/bin/fdk", "/function/func.py", "handler"] |
import os import sys import io import json from fdk import response def handler(ctx, data: io.BytesIO=None): """ input is '{"compute" : "some oci compute"}', invoke function as: $ echo -n '{"ocicompute" : "some-oci-compute-fqdn"}' | fn -v invoke ldap-app fn-python """ body = json.loads(data.getvalue()) ocicompute = body["ocicompute"] resp = ldap_cfg(ocicompute) return response.Response( ctx, response_data=json.dumps(resp), headers={"Content-Type": "application/json"} ) # ----- my code def ldap_cfg(ocicompute): opc_public_key="/home/fn/.ssh/id_rsa-opc" try: os.system('ssh -i %s -o "StrictHostKeyChecking no" opc@%s "sudo bash -s" < /function/ldap_config.sh >/dev/null' % (opc_public_key, ocicompute)) except Exception as err: # general exception sys.exit("Error: {0}".format(err)) resp = ("LDAP is configured on " + ocicompute) return resp |
schema_version: 20180708 name: fn-python version: 0.0.1 runtime: python entrypoint: /usr/local/bin/fdk /function/func.py handler memory: 256 timeout: 120 |
Syntax: fn -v deploy <application-name> Example: fn -v deploy --app ldap-app |
Syntax: $ echo -n '{"ocicompute" : "some-oci-compute-name"}' | fn -v invoke <applicattion-name> <function-name> Ex: $ echo -n '{"ocicompute" : "instance-20200706-2139.devops.tenancylhr.oraclevcn.com"}' | fn -v invoke ldap-app fn-python |