-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (69 loc) · 2.13 KB
/
containers-ctfd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Deploy containers to Hosted CTFd
on:
push:
branches:
- main
# TODO match on regex instead
paths:
- pwn/**
- web/**
workflow_dispatch:
jobs:
main:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: 3.x
cache: pip
- name: Setup ctfcli
run: |
pip install -r requirements.txt
mkdir .ctf
cat <<EOF > .ctf/config
[config]
url = https://${{ vars.CTFD_DOMAIN }}
access_token = ${{ secrets.CTFD_TOKEN }}
[cookies]
site_password = ${{ secrets.CTFD_SITE_PASSWORD }}
[challenges]
EOF
shopt -s extglob
for chal in ?(pwn|web)/*/; do
echo "$chal = $chal" >> .ctf/config
done
- uses: docker/[email protected]
- name: Get auth params for buildx cache
uses: crazy-max/[email protected]
# TODO raise issue, throws error even if target challenge isn't deployable. ignore all errors for now
- name: Deploy containers
run: |
docker() {
if [ "$1" = "build" ]; then
command docker buildx build --cache-from type=gha --cache-to type=gha,mode=max "${@:2}"
else
command docker "$@"
fi
}
ctf challenge deploy || true
- name: Setup GitHub container registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Push container images to GitHub
run: |-
images=$(docker images $REGISTRY/*:latest --format "{{.Repository}}")
for image in $images; do
lowercase=${GITHUB_REPOSITORY_OWNER,,}
newtag=${image//$REGISTRY/ghcr\.io\/$lowercase}:latest
docker tag $image:latest $newtag
docker push $newtag
done
env:
REGISTRY: ${{ vars.REGISTRY }}