Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: fix docker pushes #91

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions test/run → .github/workflows/test.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
#!/bin/sh

set -o errexit
set -o xtrace
#!/usr/bin/env bash
set -exuo pipefail

# test a docker process
docker ps | grep -q caddy-gen

# test availability and status code
curl 127.0.0.1:80

# test image size (see wemake-services/docker-image-size-limit)
disl caddy-gen:latest 100MB
# test image size < 100MB
(( $(docker inspect caddy-gen:latest -f '{{.Size}}') < 100 * 2**20 ))

# test feature CADDY_TEMPLATE
printf 'http://test-template.localhost {\n respond "template"\n}\n' > template.tmpl
docker cp template.tmpl caddy-gen:/tmp/template.tmpl
printf 'http://test-template.localhost {\n respond "template"\n}\n' > /tmp/template.tmpl
docker cp /tmp/template.tmpl caddy-gen:/tmp/template.tmpl
docker exec caddy-gen sh -c 'export CADDY_TEMPLATE=/tmp/template.tmpl && sh /code/docker-entrypoint.sh'
sleep 2
test "$(curl 0.0.0.0:80 -s -H 'Host: test-template.localhost')" = 'template'

# test feature CADDY_SNIPPET
printf 'http://test-snippet.localhost {\n respond "snippet"\n}\n' > snippet.tmpl
docker cp snippet.tmpl caddy-gen:/tmp/snippet.tmpl
printf 'http://test-snippet.localhost {\n respond "snippet"\n}\n' > /tmp/snippet.tmpl
docker cp /tmp/snippet.tmpl caddy-gen:/tmp/snippet.tmpl
docker exec caddy-gen sh \
-c 'export CADDY_TEMPLATE=/tmp/template.tmpl CADDY_SNIPPET=/tmp/snippet.tmpl && sh /code/docker-entrypoint.sh'
sleep 2
Expand Down
70 changes: 53 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,66 @@
name: test

on:
push:
branches:
- master
branches: [master]
tags: ['**']
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.head_ref || github.run_id }}
concurrency:
group: ${{ github.ref }}
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Run tests
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.ref }} # fix SHA
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: meta
with:
images: |
ghcr.io/${{ github.repository }}
wemakeservices/caddy-gen
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
labels: |
org.opencontainers.image.licenses=MIT
- uses: docker/login-action@v3
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags')
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- uses: docker/login-action@v3
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags')
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: docker build
uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
load: true
tags: caddy-gen:latest
- name: test
run: |
sh test/setup
# wait for container to start:
sleep 5
sh test/run
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro --name caddy-gen caddy-gen:latest
sleep 5 # wait for container to start
./.github/workflows/test.sh
- name: docker push
uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
push: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags') }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ version: "3"
services:
caddy-gen:
container_name: caddy-gen
image: "wemakeservices/caddy-gen:latest"
image: wemakeservices/caddy-gen:latest # or ghcr.io/wemake-services/caddy-gen:latest
restart: always
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro # needs socket to read events
Expand Down Expand Up @@ -112,7 +112,7 @@ services:
- ./caddy-info:/data/caddy
```

### Add or modify reverse_proxy headers
### Add or modify reverse_proxy headers

With the following settings, the upstream host will see its own address instead
of the original incoming value. See [Headers](https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#headers).
Expand All @@ -121,7 +121,7 @@ of the original incoming value. See [Headers](https://caddyserver.com/docs/caddy
version: "3"
services:
caddy-gen:
image: "wemakeservices/caddy-gen:latest"
image: wemakeservices/caddy-gen:latest # or ghcr.io/wemake-services/caddy-gen:latest
restart: always
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro # needs socket to read events
Expand Down Expand Up @@ -152,7 +152,7 @@ and only requests to `/api/*` will be routed to the whoami service. See
version: "3"
services:
caddy-gen:
image: "wemakeservices/caddy-gen:latest"
image: wemakeservices/caddy-gen:latest # or ghcr.io/wemake-services/caddy-gen:latest
restart: always
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro # needs socket to read events
Expand Down
11 changes: 0 additions & 11 deletions test/setup

This file was deleted.

Loading