Skip to content

Commit 8dedd1c

Browse files
authored
github actions workflow (#15)
1 parent 99332f9 commit 8dedd1c

5 files changed

Lines changed: 138 additions & 200 deletions

File tree

.github/workflows/nginx.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: build image
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
workflow_dispatch:
9+
inputs:
10+
buildtype:
11+
description: 'Build by "force" or on "change"'
12+
required: true
13+
default: 'force'
14+
repository_dispatch:
15+
types: nginx
16+
17+
jobs:
18+
19+
compare:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
flag: ${{ steps.set-flag.outputs.flag }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
arch: [amd64, arm, arm64]
27+
steps:
28+
- name: checkout repository
29+
uses: actions/checkout@v2
30+
- name: container registries
31+
run: |
32+
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
33+
docker login docker.io -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }}
34+
- name: compare image
35+
id: set-flag
36+
run: |
37+
export DOCKER_CLI_EXPERIMENTAL=enabled
38+
repo="treehouses/nginx-tags:${{ matrix.arch }}"
39+
base="treehouses/alpine-tags:${{ matrix.arch }}"
40+
docker pull -q $base &>/dev/null
41+
docker pull -q $repo &>/dev/null
42+
basesha=$(docker image inspect $base | jq --raw-output '.[0].RootFS.Layers|.[]')
43+
reposha=$(docker image inspect $repo | jq --raw-output '.[0].RootFS.Layers|.[]')
44+
echo "base sha:$basesha repo sha:$reposha"
45+
${{ github.event.inputs.buildtype == 'force' }} && echo "::set-output name=flag::true" || echo "building on change"
46+
[[ $reposha == *$basesha* ]] && echo "no changes" || echo "::set-output name=flag::true"
47+
48+
images:
49+
needs: compare
50+
runs-on: ubuntu-latest
51+
outputs:
52+
build: ${{ steps.set-build.outputs.build }}
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
arch: [amd64, arm, arm64]
57+
steps:
58+
- name: checkout repository
59+
uses: actions/checkout@v2
60+
- name: container registries
61+
run: |
62+
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
63+
docker login docker.io -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }}
64+
- name: docker image
65+
if: ${{ needs.compare.outputs.flag }}
66+
id: set-build
67+
run: |
68+
export DOCKER_CLI_EXPERIMENTAL=enabled
69+
base="treehouses/alpine-tags:${{ matrix.arch }}"
70+
repo="treehouses/nginx-tags"
71+
dest="$repo:${{ matrix.arch }}"
72+
date="$(date +%Y%m%d%H%M)"
73+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
74+
docker build -t ghcr.io/$dest --build-arg BASE=$base .
75+
docker tag ghcr.io/$dest docker.io/$dest
76+
docker tag ghcr.io/$dest ghcr.io/$dest-$date
77+
docker tag docker.io/$dest docker.io/$dest-$date
78+
docker push --all-tags ghcr.io/$repo
79+
docker push --all-tags docker.io/$repo
80+
docker images
81+
echo "::set-output name=build::true"
82+
83+
manifests:
84+
needs: images
85+
strategy:
86+
fail-fast: false
87+
matrix:
88+
registry: [docker.io, ghcr.io]
89+
runs-on: ubuntu-latest
90+
outputs:
91+
send: ${{ steps.set-send.outputs.send }}
92+
steps:
93+
- name: container registries
94+
run: |
95+
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
96+
docker login docker.io -u ${{ secrets.DOCKERUSERNAME }} -p ${{ secrets.DOCKERAPIKEY }}
97+
- name: create manifests
98+
if: ${{ needs.images.outputs.build }}
99+
id: set-send
100+
run: |
101+
repo="${{ matrix.registry }}/treehouses/nginx"
102+
date="$(date +%Y%m%d%H%M)"
103+
docker manifest create $repo:latest $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64
104+
docker manifest create $repo:$date $repo-tags:amd64 $repo-tags:arm $repo-tags:arm64
105+
docker manifest annotate $repo:latest $repo-tags:arm --os linux --arch arm
106+
docker manifest annotate $repo:$date $repo-tags:arm --os linux --arch arm
107+
docker manifest inspect $repo:latest
108+
docker manifest push $repo:latest
109+
docker manifest push $repo:$date
110+
echo "::set-output name=send::true"
111+
112+
message:
113+
needs: manifests
114+
runs-on: ubuntu-latest
115+
steps:
116+
- name: message chat of new image
117+
if: ${{ needs.manifests.outputs.send }}
118+
run: |
119+
sudo npm install -g @treehouses/cli
120+
export gitter_channel="${{ secrets.CHANNEL }}"
121+
echo "https://hub.docker.com/r/treehouses/nginx/tags"
122+
echo "https://github.com/treehouses/nginx/pkgs/container/nginx"
123+
treehouses feedback "new treehouses/nginx check https://hub.docker.com/r/treehouses/nginx/tags or https://github.com/treehouses/nginx/pkgs/container/nginx"

.travis.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ARG BASE=
2+
FROM ${BASE}
3+
4+
RUN apk --no-cache update && apk add nginx \
5+
&& mkdir -p /run/nginx \
6+
&& sed -i "s/ssl_session_cache shared:SSL:2m;/#ssl_session_cache shared:SSL:2m;/g" /etc/nginx/nginx.conf
7+
8+
COPY default.conf /etc/nginx/conf.d
9+
10+
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
11+
&& ln -sf /dev/stderr /var/log/nginx/error.log
12+
13+
EXPOSE 80 443
14+
15+
CMD ["nginx", "-g", "daemon off;"]

Dockerfile.template

Lines changed: 0 additions & 22 deletions
This file was deleted.

utils.sh

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)