Skip to content

Commit

Permalink
docker container release
Browse files Browse the repository at this point in the history
  • Loading branch information
kmlebedev committed Sep 21, 2022
1 parent 1ed2605 commit 4527c20
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/binaries_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
runs-on: self-hosted
strategy:
matrix:
goos: [windows]
goarch: [amd64]
goos: [windows, linux, darwin]
goarch: [amd64, arm64]

steps:
- name: Check out code into the Go module directory
Expand All @@ -28,6 +28,7 @@ jobs:
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
overwrite: true
pre_command: export CGO_ENABLED=0 && export GODEBUG=http2client=0
binary_name: "netcitybot"
ldflags: "-extldflags -static -s -w"
asset_name: "netcitybot_${{ matrix.goos }}_${{ matrix.goarch }}"
57 changes: 57 additions & 0 deletions .github/workflows/container_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "docker: build release containers for normal volume"

on:
push:
tags:
- '*'
workflow_dispatch: {}

permissions:
contents: read

jobs:
build-default-release-container:
runs-on: self-hosted

steps:
-
name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v2
-
name: Docker meta
id: docker_meta
uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a # v3
with:
images: |
kmlebedev/netcitybot
tags: |
type=ref,event=tag
flavor: |
latest=false
labels: |
org.opencontainers.image.title=netcitybot
org.opencontainers.image.description=NetCityBot is a API client and telegram bot for "Network City. Education" written in Golang
org.opencontainers.image.vendor=Konstantin Lebedev
-
name: Set up QEMU
uses: docker/setup-qemu-action@8b122486cedac8393e77aa9734c3528886e4a1a8 # v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@dc7b9719a96d48369863986a06765841d7ea23f6 # v1
-
name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b # v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build
uses: docker/build-push-action@c84f38281176d4c9cdb1626ffafcd6b3911b5d94 # v2
with:
context: ./docker
push: ${{ github.event_name != 'pull_request' }}
file: ./docker/Dockerfile.go_build
platforms: linux/amd64, linux/arm64
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ build:
dev: build
docker build --no-cache -t kmlebedev/netcitybot:dev -f docker/Dockerfile.local .

dev_go_build: build
docker build --no-cache -t kmlebedev/netcitybot:dev -f docker/Dockerfile.local_go_build .

go_build:
docker build --no-cache -t kmlebedev/netcitybot:local -f docker/Dockerfile.go_build .

Expand Down
13 changes: 7 additions & 6 deletions docker/Dockerfile.go_build
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
FROM golang:1.19-alpine as builder
ENV GOARCH=amd64

COPY ./ /go/src/github.com/kmlebedev/netcitybot/
WORKDIR /go/src/github.com/kmlebedev/netcitybot
RUN apk add git
RUN mkdir -p /go/src/github.com/kmlebedev/netcitybot && \
git clone --branch main https://github.com/kmlebedev/netcitybot /go/src/github.com/kmlebedev/netcitybot

RUN go mod download && GOOS=linux CGO_ENABLED=0 go build -ldflags "-extldflags -static"
RUN cd /go/src/github.com/kmlebedev/netcitybot && \
CGO_ENABLED=0 GODEBUG=http2client=0 go install -ldflags "-extldflags -static"

FROM alpine AS final

COPY ./netcitybot /usr/bin/
LABEL author="Konstantin Lebedev"
COPY --from=builder /go/bin/netcitybot /usr/bin/

ENTRYPOINT ["/usr/bin/netcitybot"]
13 changes: 13 additions & 0 deletions docker/Dockerfile.local_go_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.19-alpine as builder
ENV GOARCH=amd64

COPY ./ /go/src/github.com/kmlebedev/netcitybot/
WORKDIR /go/src/github.com/kmlebedev/netcitybot

RUN go mod download && GOOS=linux CGO_ENABLED=0 go build -ldflags "-extldflags -static"

FROM alpine AS final

COPY ./netcitybot /usr/bin/

ENTRYPOINT ["/usr/bin/netcitybot"]

0 comments on commit 4527c20

Please sign in to comment.