Skip to content

Commit ebd8945

Browse files
authored
docker: build and publish images in CI (#11)
1 parent dcc1310 commit ebd8945

File tree

3 files changed

+226
-1
lines changed

3 files changed

+226
-1
lines changed

.github/workflows/docker.yml

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
name: Docker
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
paths:
8+
- 'Dockerfile'
9+
- '.github/workflows/docker.yml'
10+
release:
11+
types: [ published ]
12+
13+
jobs:
14+
buildx:
15+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
16+
runs-on: ubuntu-latest
17+
permissions:
18+
actions: write
19+
contents: read
20+
packages: write
21+
steps:
22+
- name: Cancel previous runs
23+
uses: styfle/[email protected]
24+
with:
25+
all_but_latest: true
26+
access_token: ${{ secrets.GITHUB_TOKEN }}
27+
- name: Checkout code
28+
uses: actions/checkout@v2
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v1
31+
- name: Set up Docker Buildx
32+
id: buildx
33+
uses: docker/setup-buildx-action@v1
34+
with:
35+
config-inline: |
36+
[worker.oci]
37+
max-parallelism = 2
38+
- name: Inspect builder
39+
run: |
40+
echo "Name: ${{ steps.buildx.outputs.name }}"
41+
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
42+
echo "Status: ${{ steps.buildx.outputs.status }}"
43+
echo "Flags: ${{ steps.buildx.outputs.flags }}"
44+
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
45+
- name: Login to Docker Hub
46+
uses: docker/login-action@v1
47+
with:
48+
username: ${{ secrets.DOCKERHUB_USERNAME }}
49+
password: ${{ secrets.DOCKERHUB_TOKEN }}
50+
- name: Login to GitHub Container registry
51+
uses: docker/login-action@v1
52+
with:
53+
registry: ghcr.io
54+
username: ${{ github.repository_owner }}
55+
password: ${{ secrets.GITHUB_TOKEN }}
56+
- name: Build and push images
57+
uses: docker/build-push-action@v2
58+
with:
59+
context: .
60+
platforms: linux/amd64,linux/arm64,linux/arm/v7
61+
push: true
62+
tags: |
63+
unknwon/codenotify.run:latest
64+
ghcr.io/codenotify/codenotify.run:latest
65+
- name: Send email on failure
66+
uses: dawidd6/action-send-mail@v3
67+
if: ${{ failure() }}
68+
with:
69+
server_address: smtp.mailgun.org
70+
server_port: 465
71+
username: ${{ secrets.SMTP_USERNAME }}
72+
password: ${{ secrets.SMTP_PASSWORD }}
73+
subject: GitHub Actions (${{ github.repository }}) job result
74+
75+
from: GitHub Actions (${{ github.repository }})
76+
77+
body: |
78+
The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
79+
80+
View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
81+
82+
buildx-pull-request:
83+
if: ${{ github.event_name == 'pull_request'}}
84+
runs-on: ubuntu-latest
85+
permissions:
86+
contents: read
87+
steps:
88+
- name: Checkout code
89+
uses: actions/checkout@v2
90+
- name: Set up Docker Buildx
91+
id: buildx
92+
uses: docker/setup-buildx-action@v1
93+
with:
94+
config-inline: |
95+
[worker.oci]
96+
max-parallelism = 2
97+
- name: Inspect builder
98+
run: |
99+
echo "Name: ${{ steps.buildx.outputs.name }}"
100+
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
101+
echo "Status: ${{ steps.buildx.outputs.status }}"
102+
echo "Flags: ${{ steps.buildx.outputs.flags }}"
103+
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
104+
- name: Compute short commit SHA
105+
uses: benjlevesque/[email protected]
106+
- name: Build and push images
107+
uses: docker/build-push-action@v2
108+
with:
109+
context: .
110+
platforms: linux/amd64
111+
push: true
112+
tags: |
113+
ttl.sh/codenotify/codenotify.run-${{ env.SHA }}:1d
114+
115+
# Updates to the following section needs to be synced to all release branches within their lifecycles.
116+
buildx-release:
117+
if: ${{ github.event_name == 'release' }}
118+
runs-on: ubuntu-latest
119+
permissions:
120+
actions: write
121+
contents: read
122+
packages: write
123+
steps:
124+
- name: Compute image tag name
125+
run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV
126+
- name: Checkout code
127+
uses: actions/checkout@v2
128+
- name: Set up QEMU
129+
uses: docker/setup-qemu-action@v1
130+
- name: Set up Docker Buildx
131+
id: buildx
132+
uses: docker/setup-buildx-action@v1
133+
with:
134+
config-inline: |
135+
[worker.oci]
136+
max-parallelism = 2
137+
- name: Inspect builder
138+
run: |
139+
echo "Name: ${{ steps.buildx.outputs.name }}"
140+
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
141+
echo "Status: ${{ steps.buildx.outputs.status }}"
142+
echo "Flags: ${{ steps.buildx.outputs.flags }}"
143+
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
144+
- name: Login to Docker Hub
145+
uses: docker/login-action@v1
146+
with:
147+
username: ${{ secrets.DOCKERHUB_USERNAME }}
148+
password: ${{ secrets.DOCKERHUB_TOKEN }}
149+
- name: Login to GitHub Container registry
150+
uses: docker/login-action@v1
151+
with:
152+
registry: ghcr.io
153+
username: ${{ github.repository_owner }}
154+
password: ${{ secrets.GITHUB_TOKEN }}
155+
- name: Build and push images
156+
uses: docker/build-push-action@v2
157+
with:
158+
context: .
159+
platforms: linux/amd64,linux/arm64,linux/arm/v7
160+
push: true
161+
tags: |
162+
unknwon/codenotify.run:${{ env.IMAGE_TAG }}
163+
ghcr.io/codenotify/codenotify.run:${{ env.IMAGE_TAG }}
164+
- name: Send email on failure
165+
uses: dawidd6/action-send-mail@v3
166+
if: ${{ failure() }}
167+
with:
168+
server_address: smtp.mailgun.org
169+
server_port: 465
170+
username: ${{ secrets.SMTP_USERNAME }}
171+
password: ${{ secrets.SMTP_PASSWORD }}
172+
subject: GitHub Actions (${{ github.repository }}) job result
173+
174+
from: GitHub Actions (${{ github.repository }})
175+
176+
body: |
177+
The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
178+
179+
View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM golang:alpine3.16 AS binarybuilder
2+
RUN apk --no-cache --no-progress add --virtual \
3+
build-deps \
4+
build-base \
5+
git
6+
7+
# Install Task
8+
RUN wget --quiet https://github.com/go-task/task/releases/download/v3.16.0/task_linux_amd64.tar.gz -O task_linux_amd64.tar.gz \
9+
&& sh -c 'echo "e928c2b753aee89c03b42a6b38b05043197f2e5ab1c956841357edc924633cc9 task_linux_amd64.tar.gz" | sha256sum -c' \
10+
&& tar -xzf task_linux_amd64.tar.gz \
11+
&& mv task /usr/local/bin/task
12+
13+
WORKDIR /dist
14+
COPY . .
15+
RUN task build
16+
17+
# Install Codenotify
18+
RUN GOBIN=/dist/.bin go install github.com/sourcegraph/[email protected]
19+
20+
FROM alpine:3.16
21+
RUN echo https://dl-cdn.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories \
22+
&& apk --no-cache --no-progress add \
23+
ca-certificates \
24+
git
25+
26+
# Install gosu
27+
RUN export url="https://github.com/tianon/gosu/releases/download/1.14/gosu-"; \
28+
if [ `uname -m` == "aarch64" ]; then \
29+
wget --quiet ${url}arm64 -O /usr/sbin/gosu \
30+
&& sh -c 'echo "73244a858f5514a927a0f2510d533b4b57169b64d2aa3f9d98d92a7a7df80cea /usr/sbin/gosu" | sha256sum -c'; \
31+
elif [ `uname -m` == "armv7l" ]; then \
32+
wget --quiet ${url}armhf -O /usr/sbin/gosu \
33+
&& sh -c 'echo "abb1489357358b443789571d52b5410258ddaca525ee7ac3ba0dd91d34484589 /usr/sbin/gosu" | sha256sum -c'; \
34+
else \
35+
wget --quiet ${url}amd64 -O /usr/sbin/gosu \
36+
&& sh -c 'echo "bd8be776e97ec2b911190a82d9ab3fa6c013ae6d3121eea3d0bfd5c82a0eaf8c /usr/sbin/gosu" | sha256sum -c'; \
37+
fi \
38+
&& chmod +x /usr/sbin/gosu
39+
40+
WORKDIR /app/codenotify.run/
41+
COPY --from=binarybuilder /dist/ .
42+
43+
VOLUME ["/app/codenotify.run/custom"]
44+
EXPOSE 2830
45+
CMD ["/app/codenotify.run/codenotifyd"]

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ func main() {
3434
if err != nil {
3535
log.Fatal("Failed to load configuration: %v", err)
3636
}
37-
log.Info("Available on %s", config.Server.ExternalURL)
3837

3938
f := flamego.Classic()
4039
f.Get("/", func(c flamego.Context) {
@@ -81,5 +80,7 @@ func main() {
8180
}
8281
return http.StatusAccepted, http.StatusText(http.StatusAccepted)
8382
})
83+
84+
log.Info("Available on %s", config.Server.ExternalURL)
8485
f.Run()
8586
}

0 commit comments

Comments
 (0)