Skip to content

Commit f66a7ef

Browse files
committed
Merge pull request #33 from hurtki/feature/ci-docker-image-build
add: CI build push docker image to image registry
2 parents f742eb5 + deae370 commit f66a7ef

4 files changed

Lines changed: 86 additions & 9 deletions

File tree

.github/workflows/build.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
on:
2+
push:
3+
tags:
4+
- 'v*.*.*'
5+
jobs:
6+
check-master:
7+
runs-on: ubuntu-latest
8+
outputs:
9+
proceed: ${{ steps.check.outputs.proceed }}
10+
steps:
11+
- uses: actions/checkout@v3
12+
- id: check
13+
run: |
14+
# Check, that tag is created on master
15+
BASE_BRANCH=$(git branch --contains $GITHUB_SHA | grep -v HEAD || true)
16+
echo "Branches: $BASE_BRANCH"
17+
if echo "$BASE_BRANCH" | grep -q master; then
18+
echo "proceed=true" >> $GITHUB_OUTPUT
19+
else
20+
echo "proceed=false" >> $GITHUB_OUTPUT
21+
api:
22+
runs-on: ubuntu-latest
23+
needs: check-master
24+
environment: dockerhub-push
25+
steps:
26+
- uses: actions/checkout@v3
27+
- uses: docker/login-action@v2
28+
with:
29+
username: hurtki
30+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
31+
- uses: docker/setup-buildx-action@v2
32+
- name: Docker build
33+
run: |
34+
VERSION="${GITHUB_REF_NAME#v}"
35+
docker buildx build --push -t hurtki/github-banners-api:$VERSION ./api/
36+
renderer:
37+
runs-on: ubuntu-latest
38+
needs: check-master
39+
environment: dockerhub-push
40+
steps:
41+
- uses: actions/checkout@v3
42+
- uses: docker/login-action@v2
43+
with:
44+
username: hurtki
45+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
46+
- uses: docker/setup-buildx-action@v2
47+
- name: Docker build
48+
run: |
49+
VERSION="${GITHUB_REF_NAME#v}"
50+
docker buildx build --push -t hurtki/github-banners-renderer:$VERSION ./renderer/
51+
storage:
52+
runs-on: ubuntu-latest
53+
needs: check-master
54+
environment: dockerhub-push
55+
steps:
56+
- uses: actions/checkout@v3
57+
- uses: docker/login-action@v2
58+
with:
59+
username: hurtki
60+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
61+
- uses: docker/setup-buildx-action@v2
62+
- name: Docker build
63+
run: |
64+
VERSION="${GITHUB_REF_NAME#v}"
65+
docker buildx build --push -t hurtki/github-banners-storage:$VERSION ./storage/

api/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
FROM "golang"
1+
FROM "golang" AS build
22

3-
WORKDIR /app/renderer/
3+
WORKDIR /app/
44

55
COPY go.mod go.sum ./
66

77
RUN go mod download
88

99
COPY . .
1010

11-
RUN go build -o entry
11+
RUN CGO_ENABLED=0 go build -o entry
1212

1313
RUN chmod u+x entry
1414

1515
EXPOSE 80
1616

17+
FROM alpine:latest
18+
19+
COPY --from=build /app/entry .
20+
1721
CMD ["./entry"]

renderer/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
FROM "golang"
1+
FROM "golang" AS build
22

3-
WORKDIR /app/renderer/
3+
WORKDIR /app/
44

55
COPY go.mod go.sum ./
66

77
RUN go mod download
88

99
COPY . .
1010

11-
RUN go build -o entry
11+
RUN CGO_ENABLED=0 go build -o entry
1212

1313
RUN chmod u+x entry
1414

1515
EXPOSE 80
1616

17+
FROM alpine:latest
18+
19+
COPY --from=build /app/entry .
20+
1721
CMD ["./entry"]

storage/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
FROM "golang"
1+
FROM "golang" AS build
22

3-
WORKDIR /app/renderer/
3+
WORKDIR /app/
44

55
COPY go.mod go.sum ./
66

77
RUN go mod download
88

99
COPY . .
1010

11-
RUN go build -o entry
11+
RUN CGO_ENABLED=0 go build -o entry
1212

1313
RUN chmod u+x entry
1414

1515
EXPOSE 80
1616

17+
FROM alpine:latest
18+
19+
COPY --from=build /app/entry .
20+
1721
CMD ["./entry"]

0 commit comments

Comments
 (0)