Skip to content

Commit 41632bd

Browse files
committed
create fastly-falco image
Signed-off-by: ivan katliarchuk <[email protected]>
1 parent 41cf07e commit 41632bd

File tree

4 files changed

+208
-0
lines changed

4 files changed

+208
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: fastly.falco
2+
3+
on:
4+
push:
5+
paths:
6+
- gatling/*
7+
- .github/workflows/fastly-falco.yaml
8+
workflow_dispatch:
9+
inputs:
10+
push:
11+
description: Push to docker registry
12+
required: true
13+
default: false
14+
type: boolean
15+
16+
env:
17+
WORKSPACE: fastly-falco
18+
DOCKER_REPO: cloudkats
19+
DOCKER_IMAGE: fastly-falco
20+
GREP_VERSION: "FALCO_VERSION="
21+
22+
jobs:
23+
buildonpush:
24+
name: BuildOnPush
25+
runs-on: ubuntu-latest
26+
if: >-
27+
github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'true'
28+
|| github.event_name == 'push' && (github.event.created == false && github.event.forced == false)
29+
steps:
30+
- uses: actions/[email protected]
31+
32+
- name: Login to Registry
33+
run: |
34+
echo "${DOCKER_PASSWORD}" | docker login -u ${DOCKER_USERNAME} --password-stdin
35+
env:
36+
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
37+
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
38+
39+
- name: prepare
40+
id: prep
41+
working-directory: ${{ env.WORKSPACE }}
42+
run: |
43+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
44+
# Strip "v" prefix from tag name
45+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
46+
47+
IMAGE_ID="${DOCKER_REPO}/${DOCKER_IMAGE}"
48+
49+
echo "::set-output name=ACTION_RUN_URL::https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
50+
echo "::set-output name=ACTION_WORKFLOW_URL::https://github.com/${{github.repository}}/actions/workflows/${{github.action}}.yml"
51+
echo "::set-output name=DOCKER_VERSION::$(cat Dockerfile | grep "FALCO_VERSION=" | tr "=" " " | awk '{print $3}')"
52+
53+
echo ::set-output name=version::${VERSION}
54+
echo ::set-output name=tag_date::$(date -u +'%Y-%m')
55+
echo ::set-output name=sha::${GITHUB_SHA::8}
56+
echo ::set-output name=image_id::${IMAGE_ID}
57+
58+
- name: build & push docker image
59+
working-directory: ${{ env.WORKSPACE }}
60+
env:
61+
IMAGE_ID: ${{ steps.prep.outputs.image_id }}
62+
IMAGE: ${{ env.DOCKER_IMAGE }}
63+
TAG_VERSION_DATE: ${{ steps.prep.outputs.tag_date }}
64+
TAG_VERSION_SHA: ${{ steps.prep.outputs.sha }}
65+
TAG_VERSION: ${{ steps.prep.outputs.version }}
66+
CREATED: ${{ steps.prep.outputs.tag_date }}
67+
BUILD_URL: ${{ steps.prep.outputs.action_run_url }}
68+
IMAGE_VERSION: ${{ steps.prep.outputs.docker_version }}
69+
run: |
70+
../bin/build.sh
71+
../bin/push.sh
72+
73+
- name: docker hub description
74+
uses: peter-evans/[email protected]
75+
with:
76+
username: ${{ secrets.DOCKERHUB_USERNAME }}
77+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
78+
repository: ${{ env.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}
79+
readme-filepath: ${{ env.WORKSPACE }}/README.md
80+
short-description: "Unoficial Docker image with Fastly Falco, a VCL testing tooling"
81+
82+
build-on-merge-request:
83+
name: build-on-merge-request
84+
runs-on: ubuntu-latest
85+
if: >-
86+
github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'false'
87+
|| github.event_name == 'push' && (github.event.created == true || github.event.forced == true)
88+
steps:
89+
- uses: actions/[email protected]
90+
91+
- uses: brpaz/[email protected]
92+
env:
93+
XDG_CONFIG_HOME: ${{ env.WORKSPACE }}/hadolint.yaml
94+
with:
95+
dockerfile: ${{ env.WORKSPACE }}/Dockerfile
96+
97+
- name: prepare
98+
id: prep
99+
working-directory: ${{ env.WORKSPACE }}
100+
run: |
101+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
102+
# Strip "v" prefix from tag name
103+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
104+
105+
IMAGE_ID="${DOCKER_REPO}/${DOCKER_IMAGE}"
106+
107+
echo "::set-output name=ACTION_RUN_URL::https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
108+
echo "::set-output name=ACTION_WORKFLOW_URL::https://github.com/${{github.repository}}/actions/workflows/${{github.action}}.yml"
109+
echo "::set-output name=DOCKER_VERSION::$(cat Dockerfile | grep "$GREP_VERSION" | tr "=" " " | awk '{print $3}')"
110+
111+
echo ::set-output name=version::${VERSION}
112+
echo ::set-output name=tag_date::$(date -u +'%Y-%m')
113+
echo ::set-output name=sha::${GITHUB_SHA::8}
114+
echo ::set-output name=image_id::${IMAGE_ID}
115+
116+
- name: build
117+
working-directory: ${{ env.WORKSPACE }}
118+
env:
119+
IMAGE_ID: ${{ steps.prep.outputs.image_id }}
120+
IMAGE: ${{ env.DOCKER_IMAGE }}
121+
TAG_VERSION_DATE: ${{ steps.prep.outputs.tag_date }}
122+
TAG_VERSION_SHA: ${{ steps.prep.outputs.sha }}
123+
TAG_VERSION: ${{ steps.prep.outputs.version }}
124+
CREATED: ${{ steps.prep.outputs.tag_date }}
125+
BUILD_URL: ${{ steps.prep.outputs.action_run_url }}
126+
IMAGE_VERSION: ${{ steps.prep.outputs.docker_version }}
127+
run: |
128+
../bin/build.sh

fastly-falco/Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# COMMANDS
2+
# docker build . -t local-fastly-falco
3+
# docker run -it --rm local-fastly-falco
4+
5+
# ==========================
6+
# Stage 1: Build Falco
7+
# ==========================
8+
FROM golang:1.21-alpine AS builder
9+
10+
RUN apk add --no-cache git
11+
12+
# working directory for gatling
13+
WORKDIR /opt
14+
15+
# renovate: datasource=github-releases depName=ysugimoto/falco
16+
ENV FALCO_VERSION=v1.20.0
17+
ENV CGO_ENABLED=0
18+
# Install falco (no need to clone)
19+
RUN go install github.com/ysugimoto/falco/cmd/falco@${FALCO_VERSION}
20+
21+
# ==========================
22+
# Stage 2: Minimal runtime
23+
# ==========================
24+
FROM alpine:3.20
25+
26+
# renovate: datasource=github-releases depName=ysugimoto/falco
27+
ENV FALCO_VERSION=1.20.0
28+
29+
# Only extra tool requested
30+
RUN apk add --no-cache --progress bash \
31+
&& rm -rf /var/lib/apt/lists/* \
32+
&& rm -rf /tmp/*
33+
34+
COPY --from=builder /go/bin/falco /usr/local/bin/falco
35+
COPY entrypoint.sh /usr/local/bin/
36+
RUN chmod +x /usr/local/bin/entrypoint.sh
37+
38+
# Metadata
39+
LABEL org.opencontainers.image.authors="[email protected]" \
40+
org.opencontainers.image.vendor="https://github.com/cloudkats" \
41+
org.opencontainers.image.title="cloudkats/fastly-falco" \
42+
org.opencontainers.image.source="https://github.com/ysugimoto/falco" \
43+
org.opencontainers.image.documentation="https://github.com/cloudkats/docker-tools/fastly-falco/readme.md" \
44+
org.opencontainers.image.licenses="https://github.com/cloudkats/docker-tools/LICENCE" \
45+
org.opencontainers.image.version="${FALCO_VERSION}" \
46+
org.opencontainers.image.tools="fastly-falco"
47+
48+
# change context to opt directory
49+
WORKDIR /opt
50+
51+
ENTRYPOINT ["entrypoint.sh"]
52+
CMD ["bash"]

fastly-falco/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Falco
2+
3+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
4+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
5+
### Table of Contents
6+
7+
- [Tools installed](#tools-installed)
8+
9+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
10+
11+
## Tools installed
12+
13+
- [Falco](https://github.com/ysugimoto/falco)
14+
- [Fastly VCL](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/about-fastly-vcl/)

fastly-falco/entrypoint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
[[ ${DEBUG:-} ]] && set -x
6+
7+
# first arg is `-f` or `--some-option`
8+
# or there are no args
9+
if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
10+
# docker run bash -c 'echo hi'
11+
exec bash "$@"
12+
fi
13+
14+
exec "$@"

0 commit comments

Comments
 (0)