-
-
Notifications
You must be signed in to change notification settings - Fork 2
118 lines (104 loc) · 4.85 KB
/
docker.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Docker
on:
push:
tags:
- "sushii-2-v*"
- "sushii-api-v*"
- "sushii-feeds-v*"
- "sushii-webhooks-v*"
env:
SUSHII_2_IMAGE_NAME: ghcr.io/sushiibot/sushii-2
SUSHII_API_IMAGE_NAME: ghcr.io/sushiibot/sushii-api
SUSHII_FEEDS_IMAGE_NAME: ghcr.io/sushiibot/sushii-feeds
SUSHII_WEBHOOKS_IMAGE_NAME: ghcr.io/sushiibot/sushii-webhooks
jobs:
push:
name: Build and publish Docker Image
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Select image
id: docker_image_select
run: |
echo ${GITHUB_REF#refs/*/}
if [[ ${GITHUB_REF#refs/*/} == sushii-2* ]]
then
echo ::set-output name=image::${{ env.SUSHII_2_IMAGE_NAME}}
echo ::set-output name=docker_file::"./sushii-2/Dockerfile"
echo ::set-output name=title::"sushii-2"
echo ::set-output name=description::"Moderation bot for Discord"
exit 0
fi
if [[ ${GITHUB_REF#refs/*/} == sushii-api* ]]
then
echo ::set-output name=image::${{ env.SUSHII_API_IMAGE_NAME}}
echo ::set-output name=docker_file::"./sushii-api/Dockerfile"
echo ::set-output name=title::"sushii-api"
echo ::set-output name=description::"GraphQL API server for sushii2"
exit 0
fi
if [[ ${GITHUB_REF#refs/*/} == sushii-feeds* ]]
then
echo ::set-output name=image::${{ env.SUSHII_FEEDS_IMAGE_NAME}}
echo ::set-output name=docker_file::"./sushii-feeds/Dockerfile"
echo ::set-output name=title::"sushii-feeds"
echo ::set-output name=description::"gRPC feed fetching service for sushii2"
exit 0
fi
if [[ ${GITHUB_REF#refs/*/} == sushii-webhooks* ]]
then
echo ::set-output name=image::${{ env.SUSHII_WEBHOOKS_IMAGE_NAME}}
echo ::set-output name=docker_file::"./Dockerfile"
echo ::set-output name=title::"sushii-webhooks"
echo ::set-output name=build_args::"TARGET=sushii-webhooks"
echo ::set-output name=description::"Webhook service for sushii"
exit 0
fi
echo "Tags did not match packages"
exit 1
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ${{ steps.docker_image_select.outputs.image}}
tag-match: "v(.*)"
tag-match-group: "1"
tag-sha: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Github Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and push image to GitHub Packages
uses: docker/build-push-action@v2
with:
context: .
build-args: ${{ steps.docker_image_select.outputs.build_args }}
file: ${{ steps.docker_image_select.outputs.docker_file }}
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
tags: ${{ steps.docker_meta.outputs.tags }}
labels: |
${{ steps.docker_meta.outputs.labels }}
org.opencontainers.image.title=${{ steps.docker_image_select.outputs.title }}
org.opencontainers.image.description=${{ steps.docker_image_select.outputs.description }}
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache