Skip to content

Commit

Permalink
Add dockerhub lates tag
Browse files Browse the repository at this point in the history
  • Loading branch information
outdead committed Mar 9, 2022
1 parent 3c1c0c1 commit 6cdb1be
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 31 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,30 @@ jobs:

- name: Build
run: go build -v .

docker-release:
name: Docker Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to docker.io
run: docker login -u outdead -p ${{ secrets.GORCON_DOCKER_TOKEN }}

- name: Build and publish
uses: docker/build-push-action@v2
with:
context: .
file: build/docker/Dockerfile
push: true
build-args: |
VERSION=0.0.0-develop
tags: |
outdead/rcon:latest
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.idea/
.vscode/

vendor/
release/
logs/

*local.yaml
rcon-cli
rcon-cli.exe
gorcon
*.log
.tmp/
.env
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.

## [Unreleased]
### Added
- Added `--timeout, -T` flag, allowed to set dial and execute timeout.
- Added `--timeout, -T` flag, allowed to set dial and execute timeout.

## [v0.10.1] - 2021-11-13
### Fixed
Expand Down
16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include scripts/*.mk

.DEFAULT_GOAL := nothing

nothing:
@echo "nothing to do"
1 change: 1 addition & 0 deletions build/docker/.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION=docker
25 changes: 25 additions & 0 deletions build/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Stage 1 - Build the code.
FROM golang:1.16.7-alpine as builder

RUN apk --no-cache add --update gcc musl-dev

ARG VERSION=docker

WORKDIR /build
COPY cmd cmd
COPY internal internal
COPY go.mod .
COPY go.sum .
RUN CGO_ENABLED=1 go build -ldflags "-s -w -X main.ServiceVersion=${VERSION}" -o gorcon ./cmd/gorcon/main.go

# Stage 2 - Create image.
FROM alpine as runner
MAINTAINER Pavel Korotkiy <paul.korotkiy@gmail.com>

COPY LICENSE /
COPY README.md /
COPY CHANGELOG.md /
COPY rcon.yaml /
COPY --from=builder /build/gorcon /rcon

CMD ["/rcon"]
File renamed without changes.
28 changes: 28 additions & 0 deletions scripts/docker/docker.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
include build/docker/.env
export

## If the first argument is "docker-deploy"...
#ifeq (docker-run, $(firstword $(MAKECMDGOALS)))
# # use the rest as arguments for "run"
# RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# # ...and turn them into do-nothing targets
# $(eval $(RUN_ARGS):;@:)
#endif

IMAGES := `docker images --filter "dangling=true" -q --no-trunc`

docker-clean:
docker rmi ${IMAGES} 2> /dev/null ||:

docker-build:
docker build -f build/docker/Dockerfile \
--build-arg VERSION="${VERSION}" \
-t outdead/rcon .

docker rmi ${IMAGES} 2> /dev/null ||:

# make docker-run e=pz4 command=players
docker-run:
docker run -it --rm \
-v $(CURDIR)/rcon-local.yaml:/rcon.yaml \
outdead/rcon ./rcon -c rcon.yaml -e $(e) $(command)
22 changes: 12 additions & 10 deletions release.sh → scripts/local/build.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
#!/usr/bin/env bash

VERSION="$1"
if [ -z "${VERSION}" ]; then echo "VERSION is not set. Use ./release.sh 0.0.0" >&2; exit 1; fi
if [ -z "${VERSION}" ]; then echo "VERSION is not set. Use ./build.sh 0.0.0" >&2; exit 1; fi

rm -r release
mkdir release
touch release/checksum.txt
RELEASE_DIR=".tmp/release"

function make_release() {
rm -r "${RELEASE_DIR}"
mkdir "${RELEASE_DIR}"
touch "${RELEASE_DIR}/checksum.txt"

make_release() {
local arch="$1"
local os="$2"
local release_name="$3"
if [ -z "${arch}" ] || [ -z "${os}" ] || [ -z "${release_name}" ]; then echo "args are not set" >&2; return 1; fi

local ext="$4"

local dir="release/${release_name}"
local dir="${RELEASE_DIR}/${release_name}"

mkdir -p "${dir}"
env GOARCH="${arch}" GOOS="${os}" CGO_ENABLED=0 go build -ldflags "-s -w -X main.Version=${VERSION}" -o "${dir}/rcon${ext}"
env GOARCH="${arch}" GOOS="${os}" CGO_ENABLED=0 go build -ldflags "-s -w -X main.Version=${VERSION}" -o "${dir}/rcon${ext}" ./cmd/gorcon/main.go

cp LICENSE "${dir}"
cp README.md "${dir}"
cp CHANGELOG.md "${dir}"
cp rcon.yaml "${dir}"

cd release/
cd "${RELEASE_DIR}/"
case "${os}" in
linux | darwin)
tar -zcvf "${release_name}.tar.gz" "${release_name}"
Expand All @@ -37,7 +39,7 @@ function make_release() {
;;
esac
rm -r "${release_name}"
cd ../
cd ../../
}

make_release 386 linux "rcon-${VERSION}-i386_linux"
Expand All @@ -46,4 +48,4 @@ make_release 386 windows "rcon-${VERSION}-win32" .exe
make_release amd64 windows "rcon-${VERSION}-win64" .exe
make_release amd64 darwin "rcon-${VERSION}-amd64_darwin"

env GOARCH="amd64" GOOS="linux" CGO_ENABLED=0 go build -ldflags "-s -w -X main.Version=${VERSION}"
env GOARCH="amd64" GOOS="linux" CGO_ENABLED=0 go build -ldflags "-s -w -X main.Version=${VERSION}" -o gorcon ./cmd/gorcon/main.go
16 changes: 16 additions & 0 deletions scripts/local/local.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# If the first argument is "docker-deploy"...
ifeq (build, $(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "run"
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(RUN_ARGS):;@:)
endif

build:
sh scripts/local/build.sh $(RUN_ARGS)

run:
sh scripts/local/run.sh

lint:
golangci-lint run
3 changes: 3 additions & 0 deletions scripts/local/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

go run cmd/gorcon/main.go -c rcon-local.yaml
2 changes: 2 additions & 0 deletions scripts/scripts.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include scripts/docker/docker.mk
include scripts/local/local.mk

0 comments on commit 6cdb1be

Please sign in to comment.