Skip to content

Commit

Permalink
CI: fix docker pushes (#91)
Browse files Browse the repository at this point in the history
Co-authored-by: sobolevn <mail@sobolevn.me>
  • Loading branch information
casperdcl and sobolevn authored Aug 13, 2024
1 parent fb62234 commit 1b1d9b9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 42 deletions.
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
67 changes: 50 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,63 @@
name: test

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

concurrency:
group: ${{ github.head_ref || github.run_id }}
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
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
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: meta
with:
python-version: '3.9'

- name: Run tests
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.

0 comments on commit 1b1d9b9

Please sign in to comment.