├── test ├── .gitignore ├── simple.yml ├── multi-function.yml ├── first │ └── Dockerfile ├── second │ └── Dockerfile └── simple │ └── Dockerfile ├── .gitignore ├── Dockerfile ├── LICENSE ├── action.yml ├── README.md ├── entrypoint.sh └── .github └── workflows └── main.yml /test/.gitignore: -------------------------------------------------------------------------------- 1 | template 2 | build 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | template 3 | build 4 | -------------------------------------------------------------------------------- /test/simple.yml: -------------------------------------------------------------------------------- 1 | version: 1.0 2 | provider: 3 | name: openfaas 4 | gateway: http://127.0.0.1:31112 5 | functions: 6 | simple: 7 | lang: dockerfile 8 | handler: ./simple 9 | image: mrsimpson/unit-test-simple:latest 10 | 11 | -------------------------------------------------------------------------------- /test/multi-function.yml: -------------------------------------------------------------------------------- 1 | version: 1.0 2 | provider: 3 | name: openfaas 4 | gateway: http://127.0.0.1:31112 5 | functions: 6 | first: 7 | lang: dockerfile 8 | handler: ./first 9 | image: mrsimpson/unit-test-first:latest 10 | 11 | second: 12 | lang: dockerfile 13 | handler: ./second 14 | image: mrsimpson/unit-test-second:latest 15 | 16 | -------------------------------------------------------------------------------- /test/first/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openfaas/classic-watchdog:0.18.1 as watchdog 2 | 3 | FROM alpine:3.11 4 | 5 | RUN mkdir -p /home/app 6 | 7 | COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog 8 | RUN chmod +x /usr/bin/fwatchdog 9 | 10 | # Add non root user 11 | RUN addgroup -S app && adduser app -S -G app 12 | RUN chown app /home/app 13 | 14 | WORKDIR /home/app 15 | 16 | USER app 17 | 18 | # Populate example here - i.e. "cat", "sha512sum" or "node index.js" 19 | ENV fprocess="echo first" 20 | # Set to true to see request in function logs 21 | ENV write_debug="false" 22 | 23 | EXPOSE 8080 24 | 25 | HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 26 | 27 | CMD ["fwatchdog"] 28 | -------------------------------------------------------------------------------- /test/second/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openfaas/classic-watchdog:0.18.1 as watchdog 2 | 3 | FROM alpine:3.11 4 | 5 | RUN mkdir -p /home/app 6 | 7 | COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog 8 | RUN chmod +x /usr/bin/fwatchdog 9 | 10 | # Add non root user 11 | RUN addgroup -S app && adduser app -S -G app 12 | RUN chown app /home/app 13 | 14 | WORKDIR /home/app 15 | 16 | USER app 17 | 18 | # Populate example here - i.e. "cat", "sha512sum" or "node index.js" 19 | ENV fprocess="echo second" 20 | # Set to true to see request in function logs 21 | ENV write_debug="false" 22 | 23 | EXPOSE 8080 24 | 25 | HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 26 | 27 | CMD ["fwatchdog"] 28 | -------------------------------------------------------------------------------- /test/simple/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openfaas/classic-watchdog:0.18.1 as watchdog 2 | 3 | FROM alpine:3.11 4 | 5 | RUN mkdir -p /home/app 6 | 7 | COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog 8 | RUN chmod +x /usr/bin/fwatchdog 9 | 10 | # Add non root user 11 | RUN addgroup -S app && adduser app -S -G app 12 | RUN chown app /home/app 13 | 14 | WORKDIR /home/app 15 | 16 | USER app 17 | 18 | # Populate example here - i.e. "cat", "sha512sum" or "node index.js" 19 | ENV fprocess="echo simple" 20 | # Set to true to see request in function logs 21 | ENV write_debug="false" 22 | 23 | EXPOSE 8080 24 | 25 | HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 26 | 27 | CMD ["fwatchdog"] 28 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | ARG BUILDX_VERSION=19.03.5_0.3.1 2 | FROM jonoh/docker-buildx-qemu:${BUILDX_VERSION} 3 | 4 | ARG FAAS_CLI_VERSION=0.11.8 5 | # Download FaaS CLI 6 | RUN curl -sLSf -o faas-cli https://github.com/openfaas/faas-cli/releases/download/${FAAS_CLI_VERSION}/faas-cli 7 | RUN curl -sLSf -o faas-cli.sig https://github.com/openfaas/faas-cli/releases/download/${FAAS_CLI_VERSION}/faas-cli.sha256 8 | 9 | RUN shasum -a 256 faas-cli -c faas-cli.sig 2>&1 | grep OK && \ 10 | mv faas-cli /usr/local/bin/ && \ 11 | chmod +x /usr/local/bin/faas-cli 12 | 13 | # Copies your code file from your action repository to the filesystem path `/` of the container 14 | COPY entrypoint.sh /entrypoint.sh 15 | 16 | # Code file to execute when the docker container starts up (`entrypoint.sh`) 17 | ENTRYPOINT ["/entrypoint.sh"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Oliver Jägle 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | # action.yml 2 | name: 'OpenFaaS build and push' 3 | description: 'Builds a docker image from your OpenFaaS function and pushes it to your registry' 4 | branding: 5 | icon: upload-cloud 6 | color: blue 7 | inputs: 8 | stack-file: 9 | description: 'The OpenFaaS function definition file' 10 | required: true 11 | default: 'stack.yml' 12 | docker-username: 13 | description: 'Your docker username with push authorization' 14 | required: true 15 | docker-password: 16 | description: 'Your docker password' 17 | required: true 18 | platforms: 19 | description: 'the platform abbreviations to build for, e. g. linux/amd64,linux/arm/v7' 20 | required: false 21 | default: 'linux/amd64' 22 | tag-alias: 23 | description: 'the tag used to alias docker images, e.g. latest, main etc.' 24 | required: false 25 | deploy: 26 | description: 'Whether the built image shall be deployed (true/false)' 27 | required: false 28 | default: 'false' 29 | openfaas-gateway: 30 | description: 'OpenFaaS gateway URL (http(s)://my-public-gateway.tld)' 31 | required: false 32 | openfaas-username: 33 | description: 'User for authenticating at OpenFaaS gateway' 34 | required: false 35 | default: 'admin' 36 | openfaas-password: 37 | description: 'Password for authenticating at OpenFaaS gateway' 38 | required: false 39 | 40 | outputs: 41 | tag: 42 | description: 'Image tag built' 43 | runs: 44 | using: 'docker' 45 | image: 'Dockerfile' 46 | args: 47 | - ${{ inputs.stack-file }} 48 | - ${{ inputs.docker-username }} 49 | - ${{ inputs.docker-password }} 50 | - ${{ inputs.platforms }} 51 | - ${{ inputs.tag-alias }} 52 | - ${{ inputs.deploy }} 53 | - ${{ inputs.openfaas-gateway }} 54 | - ${{ inputs.openfaas-username }} 55 | - ${{ inputs.openfaas-password }} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenFaaS Github action 2 | 3 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 4 | ![CI (build and test)](https://github.com/mrsimpson/action-openfaas-build/workflows/CI/badge.svg) 5 | 6 | A no-frills [Github action](https://help.github.com/en/actions/getting-started-with-github-actions) for building OpenFaaS functions. 7 | 8 | The function gets the image information from the function file. 9 | 10 | ## Limitations 11 | 12 | No sophisticated optional parameters! The main pupose of this action is simplicity. 13 | Therefore, no other optional, non-functional parameters influencing the behaviour of `faas-cli` are going to be supported. 14 | If you really feel that you desperately need sommething, feel free to open an issue! 15 | 16 | ## Inputs 17 | 18 | | Parameter | effect | default | required | 19 | | ---- | ---- | ---- | ----- | 20 | | `stack-file` | The OpenFaaS function definition file | `stack.yml` | yes | 21 | | `docker-username` | Your docker registry's username with push authorization | ❌ | yes | 22 | | `docker-password` | Your docker registry's password | ❌ | yes | 23 | | `platforms` | The platform abbreviations to build for, potentially comma-separated. e. g. `linux/amd64,linux/arm/v7` | `linux/amd64` | yes | 24 | | `deploy` | Whether the built image shall be deployed | `false` | no | 25 | | `openfaas-gateway` | OpenFaaS gateway URL overriding the one given. Only has an effect, if `deploy=true` | | no | 26 | | `openfaas-username` | User for authenticating at OpenFaaS gateway | | no | 27 | | `openfaas-password`| Password for authenticating at OpenFaaS gateway | | no | 28 | 29 | ## Outputs 30 | 31 | | Parameter | purpose | 32 | | ---- | ---- | 33 | | `tag` | The tag of the image built - it's the same across multiple images from the same function stack build | 34 | 35 | 36 | ## Further links 37 | 38 | 🏠 [**Homepage**](https://github.com/mrsimpson/action-openfaas-build) 39 | 40 | ✨ [**Demo**](https://github.com/open-abap/openfaas-fn-fibonacci/actions) 41 | 42 | ## Author 43 | 44 | 👤 **Oliver Jägle** 45 | 46 | * Twitter: [@OJaegle](https://twitter.com/OJaegle) 47 | * Github: [@mrsimpson](https://github.com/mrsimpson) 48 | 49 | ## 🤝 Contributing 50 | 51 | Contributions, issues and feature requests are welcome! 52 | 53 | Feel free to check [issues page](https://github.com/mrsimpson/action-openfaas-build/issues). 54 | 55 | ## Show your support 56 | 57 | Give a ⭐️ if this project helped you! 58 | 59 | 60 | *** 61 | _This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_ 62 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -o pipefail 5 | 6 | STACK_FILE="$1" 7 | DOCKER_USERNAME="$2" 8 | DOCKER_PASSWORD="$3" 9 | PLATFORMS="$4" 10 | TAG_ALIAS="$5" 11 | DEPLOY="$6" 12 | GATEWAY="$7" 13 | OPENFAAS_USERNAME="$8" 14 | OPENFAAS_PASSWORD="$9" 15 | 16 | # Trigger the shrinkwrap 17 | BUILDING_MESSAGES_STRING=$(faas-cli build -f $STACK_FILE --shrinkwrap --tag sha | grep 'Building:') 18 | SHRINKWRAP_MESSAGES_STRING=$(faas-cli build -f $STACK_FILE --shrinkwrap --tag sha | grep 'shrink-wrapped') 19 | 20 | mapfile -t SHRINKWRAP_MESSAGES <<< "$SHRINKWRAP_MESSAGES_STRING" 21 | mapfile -t BUILDING_MESSAGES <<< "$BUILDING_MESSAGES_STRING" 22 | 23 | for i in "${!BUILDING_MESSAGES[@]}"; do 24 | SHRINKWRAP_MESSAGE=${SHRINKWRAP_MESSAGES[i]} 25 | BUILDING_MESSAGE=${BUILDING_MESSAGES[i]} 26 | 27 | # Parse messages 28 | IMAGE_FULL=$(echo $BUILDING_MESSAGE | cut -d' ' -f2) 29 | TAG=$(echo $IMAGE_FULL | rev | cut -f1 -d":" | rev) # part after last colon 30 | WITHOUT_TAG=$(echo $IMAGE_FULL | sed "s/:$TAG//") 31 | IMAGE=$(echo $WITHOUT_TAG | rev | cut -f1 -d"/" | rev) # part after last slash 32 | WITHOUT_IMAGE=$(echo $WITHOUT_TAG | sed "s/\/$IMAGE//") 33 | ORG=$(echo $WITHOUT_IMAGE| rev | cut -f1 -d"/" | rev) # part after last slash 34 | 35 | SLASH_COUNT=$(tr -dc '/' <<<"$IMAGE_FULL" | awk '{ print length; }') 36 | if [ $SLASH_COUNT -gt 1 ]; then 37 | REGISTRY=$(echo $WITHOUT_IMAGE | sed "s/\/$ORG//") 38 | else 39 | REGISTRY='' 40 | fi 41 | 42 | # Get mapping to functions and directories 43 | FUNCTION=$(echo $SHRINKWRAP_MESSAGE | cut -d' ' -f1) 44 | FOLDER=$(echo $SHRINKWRAP_MESSAGE | cut -d' ' -f4) 45 | 46 | # For debugging purposes 47 | echo IMAGE_FULL=$IMAGE_FULL 48 | echo REGISTRY=$REGISTRY 49 | echo ORG=$ORG 50 | echo IMAGE=$IMAGE 51 | echo TAG=$TAG 52 | echo TAG_ALIAS=$TAG_ALIAS 53 | echo FUNCTION=$FUNCTION 54 | echo FOLDER=$FOLDER 55 | 56 | # Authenticate 57 | echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin $REGISTRY 58 | 59 | # Build and push docker image 60 | cd "${FOLDER}" 61 | export DOCKER_CLI_EXPERIMENTAL=enabled 62 | docker run --rm --privileged multiarch/qemu-user-static --reset -p yes 63 | docker buildx create --use 64 | docker buildx install 65 | if [ ! -z $TAG_ALIAS ]; then 66 | ALIAS="${WITHOUT_TAG}:${TAG_ALIAS}" 67 | docker build --platform $PLATFORMS -t $IMAGE_FULL -t $ALIAS --push . 68 | else 69 | docker build --platform $PLATFORMS -t $IMAGE_FULL --push . 70 | fi 71 | cd - 72 | done 73 | 74 | # TAG is the same across all function builds 75 | echo ::set-output name=tag::$TAG 76 | 77 | # Deploy function stack if requested 78 | if [ $DEPLOY = 'true' ]; then 79 | echo "Deploying function stack" 80 | if [ -z $GATEWAY ]; then 81 | echo $OPENFAAS_PASSWORD | faas-cli login -u $OPENFAAS_USERNAME --password-stdin 82 | faas-cli deploy -f "$STACK_FILE" --image $IMAGE_FULL --tag sha 83 | else 84 | echo $OPENFAAS_PASSWORD | faas-cli login -u $OPENFAAS_USERNAME --password-stdin -g $GATEWAY 85 | faas-cli deploy -f "$STACK_FILE" --image $IMAGE_FULL --tag sha -g $GATEWAY 86 | fi 87 | fi 88 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | push: 6 | paths-ignore: 7 | - '**.md' 8 | 9 | env: 10 | DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} 11 | DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} 12 | OPENFAAS_GATEWAY: ${{ secrets.OPENFAAS_GATEWAY }} 13 | OPENFAAS_USERNAME: ${{ secrets.OPENFAAS_USERNAME }} 14 | OPENFAAS_PASSWORD: ${{ secrets.OPENFAAS_PASSWORD }} 15 | 16 | jobs: 17 | 18 | test-simple: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v2 22 | - run: | 23 | cp -Rf test/* . 24 | - name: Test setup - Build the function stack and deploy it 25 | id: build-simple 26 | uses: './' 27 | with: 28 | stack-file: './simple.yml' 29 | docker-username: ${{ env.DOCKER_USERNAME }} 30 | docker-password: ${{ env.DOCKER_PASSWORD }} 31 | platforms: linux/amd64,linux/arm/v7 32 | - name: Test execution 33 | run: | 34 | export repo=mrsimpson/unit-test-simple 35 | curl --fail -H "Authorization: Bearer $(curl --fail -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" | jq --raw-output .token)" "https://index.docker.io/v2/${repo}/manifests/${TAG}" | grep "fprocess=echo simple" 36 | env: 37 | TAG: ${{ steps.build-simple.outputs.tag }} 38 | - name: Login to Dockerhub 39 | run: | 40 | echo "::set-env name=DOCKER_JWT::$(curl --fail -s -H "Content-Type: application/json" -X POST -d "{ \"username\": \"${DOCKER_USERNAME}\", \"password\": \"${DOCKER_PASSWORD}\"}" "https://hub.docker.com/v2/users/login/" | jq -r .token)" 41 | - name: delete simple-image 42 | run: | 43 | curl --fail "https://hub.docker.com/v2/repositories/mrsimpson/unit-test-simple/tags/${TAG}/" -X DELETE -H "Authorization: JWT ${DOCKER_JWT}" 44 | env: 45 | TAG: ${{ steps.build-simple.outputs.tag }} 46 | 47 | test-multi: 48 | runs-on: ubuntu-latest 49 | steps: 50 | - uses: actions/checkout@v2 51 | - run: | 52 | cp -Rf test/* . 53 | - name: Test setup - Build the function stack and deploy it 54 | id: build-multi 55 | uses: './' 56 | with: 57 | stack-file: './multi-function.yml' 58 | docker-username: ${{ env.DOCKER_USERNAME }} 59 | docker-password: ${{ env.DOCKER_PASSWORD }} 60 | platforms: linux/amd64 61 | - name: Test execution - validate first 62 | run: | 63 | export repo=mrsimpson/unit-test-first 64 | curl --fail -H "Authorization: Bearer $(curl --fail -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" | jq --raw-output .token)" "https://index.docker.io/v2/${repo}/manifests/${TAG}" | grep "fprocess=echo first" 65 | env: 66 | TAG: ${{ steps.build-multi.outputs.tag }} 67 | - name: Test execution - validate second 68 | run: | 69 | export repo=mrsimpson/unit-test-second 70 | curl --fail -H "Authorization: Bearer $(curl --fail -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" | jq --raw-output .token)" "https://index.docker.io/v2/${repo}/manifests/${TAG}" | grep "fprocess=echo second" 71 | env: 72 | TAG: ${{ steps.build-multi.outputs.tag }} 73 | - name: Login to Dockerhub 74 | run: | 75 | echo "::set-env name=DOCKER_JWT::$(curl --fail -s -H "Content-Type: application/json" -X POST -d "{ \"username\": \"${DOCKER_USERNAME}\", \"password\": \"${DOCKER_PASSWORD}\"}" "https://hub.docker.com/v2/users/login/" | jq -r .token)" 76 | - name: delete multi-image 77 | run: | 78 | curl --fail "https://hub.docker.com/v2/repositories/mrsimpson/unit-test-first/tags/${TAG}/" -X DELETE -H "Authorization: JWT ${DOCKER_JWT}" 79 | curl --fail "https://hub.docker.com/v2/repositories/mrsimpson/unit-test-second/tags/${TAG}/" -X DELETE -H "Authorization: JWT ${DOCKER_JWT}" 80 | env: 81 | TAG: ${{ steps.build-multi.outputs.tag }} 82 | 83 | test-deploy: 84 | runs-on: ubuntu-latest 85 | 86 | steps: 87 | - uses: actions/checkout@v2 88 | - name: Install faasd 89 | if: ${{ env.OPENFAAS_GATEWAY == '' }} 90 | run: | 91 | sudo apt update 92 | sudo apt install -qy runc bridge-utils tmux git 93 | sudo curl --fail -fSLs "https://github.com/openfaas/faasd/releases/download/0.8.0/faasd" --output "/usr/local/bin/faasd" 94 | sudo chmod a+x "/usr/local/bin/faasd" 95 | export GOPATH=$HOME/go/ 96 | mkdir -p $GOPATH/src/github.com/openfaas 97 | cd $GOPATH/src/github.com/openfaas 98 | git clone https://github.com/openfaas/faasd 99 | cd faasd 100 | sudo faasd install 101 | sudo modprobe br_netfilter 102 | sudo sysctl net.bridge.bridge-nf-call-iptables=1 103 | sudo mkdir -p /opt/cni/bin 104 | curl --fail -sSL https://github.com/containernetworking/plugins/releases/download/v0.8.5/cni-plugins-linux-arm-v0.8.5.tgz | sudo tar -xz -C /opt/cni/bin 105 | sudo mkdir -p /opt/cni/bin 106 | curl --fail -sSL https://github.com/containernetworking/plugins/releases/download/v0.8.5/cni-plugins-linux-arm-v0.8.5.tgz | sudo tar -xz -C /opt/cni/bin 107 | - name: Wait for OpenFaaS to be ready 108 | if: ${{ env.OPENFAAS_GATEWAY == '' }} 109 | run: | 110 | for i in {1..10} 111 | do 112 | if [ $(sudo systemctl status faasd | grep -c 'running') -eq 0 -a $(sudo systemctl status faasd-provider | grep -c 'running') -eq 0 ]; then 113 | export RUNNING=true 114 | break 115 | else 116 | date && echo no 117 | export RUNNING=false 118 | fi 119 | sleep 5s 120 | done 121 | $RUNNING && exit 0 122 | - name: Get OpenFaaS password 123 | if: ${{ env.OPENFAAS_GATEWAY == '' }} 124 | run: | 125 | echo "FaasD status" 126 | sudo systemctl status faasd 127 | sudo journalctl -u faasd --lines 40 128 | 129 | echo "FaasD provider status" 130 | sudo systemctl status faasd-provider 131 | sudo journalctl -u faasd-provider --lines 40 132 | echo "::set-env name=OPENFAAS_PASSWORD::$(sudo cat /var/lib/faasd/secrets/basic-auth-password)" 133 | - run: | 134 | cp -Rf test/* . 135 | - name: Test setup - Build the function stack and deploy it 136 | id: build-simple 137 | uses: './' 138 | with: 139 | stack-file: './simple.yml' 140 | docker-username: ${{ env.DOCKER_USERNAME }} 141 | docker-password: ${{ env.DOCKER_PASSWORD }} 142 | platforms: linux/amd64 143 | deploy: true 144 | openfaas-gateway: ${{ env.OPENFAAS_GATEWAY || 'http://localhost:8080' }} 145 | openfaas-username: ${{ env.OPENFAAS_USERNAME || 'admin' }} 146 | openfaas-password: ${{ env.OPENFAAS_PASSWORD }} 147 | - name: Test execution - Check whether the function exists in OpenFaaS 148 | run: | 149 | code=$(curl --write-out %{http_code} --silent --output /dev/null -u $OPENFAAS_USERNAME:$OPENFAAS_PASSWORD $OPENFAAS_GATEWAY/system/function/simple) 150 | if [ $code -eq 200 ]; then 151 | exit 0; 152 | else 153 | echo "Got HTTP code ${code}"; 154 | exit 1; 155 | fi 156 | 157 | teardown-deployment: 158 | runs-on: ubuntu-latest 159 | if: always() 160 | needs: test-deploy 161 | steps: 162 | - name: delete deployed function 163 | run: | 164 | code=$(curl --write-out %{http_code} --silent --output /dev/null -u $OPENFAAS_USERNAME:$OPENFAAS_PASSWORD -X DELETE -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"functionName\": \"simple\"}" $OPENFAAS_GATEWAY/system/functions) 165 | if [ $code -eq 202 ]; then 166 | exit 0; 167 | else 168 | echo "Got HTTP code ${code}"; 169 | exit 1; 170 | fi 171 | 172 | build-and-buffer: 173 | runs-on: ubuntu-latest 174 | steps: 175 | - uses: actions/checkout@v2 176 | - name: Determine Image 177 | run: | 178 | echo "::set-env name=IMAGE_NAME::$(echo "docker.pkg.github.com/${REPOSITORY}/action:${SHA}")" 179 | echo "${IMAGE_NAME}" 180 | env: 181 | REPOSITORY: ${{ github.repository }} 182 | SHA: ${{ github.sha }} 183 | - name: Build action image 184 | run: | 185 | docker build -t ${IMAGE_NAME} . 186 | - name: publish to github registry 187 | run: | 188 | docker login docker.pkg.github.com -u "${GITHUB_ACTOR}" -p "${GITHUB_TOKEN}" 189 | docker push "${IMAGE_NAME}" 190 | env: 191 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 192 | --------------------------------------------------------------------------------