diff --git a/.dockerignore b/.dockerignore index 4fd83dea..46ed7d0a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,5 @@ .dockerignore +.git Makefile docker*.yml *.log diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 86bd9cae..e88159f5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,7 +25,7 @@ jobs: fetch-depth: 1 - name: Generate version value - run: echo "::set-env name=version::${GITHUB_REF/refs\/tags\//}@`echo ${GITHUB_SHA} | cut -c1-8`" + run: echo "::set-env name=version::${GITHUB_REF##*/}@`echo ${GITHUB_SHA} | cut -c1-8`" - name: Build application env: @@ -40,3 +40,27 @@ jobs: with: file: "./mikrotik-hosts-parser-${{ matrix.os }}-${{ matrix.arch }}" type: 'application/octet-stream' + + docker-image: + name: Build docker image + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v1 + with: + fetch-depth: 1 + + - name: Generate version value + run: echo "::set-env name=version::${GITHUB_REF##*/}@`echo ${GITHUB_SHA} | cut -c1-8`" + + - name: Generate image tag value + run: echo "::set-env name=image_tag::${GITHUB_REF##*/[vV]}" # `/refs/tags/v1.2.3` -> `1.2.3` + + - name: Make docker login + run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_LOGIN }}" --password-stdin &> /dev/null + + - name: Build image + run: docker build --build-arg "APP_VERSION=${version}" --tag "tarampampam/mikrotik-hosts-parser:${image_tag}" -f ./Dockerfile . + + - name: Push image + run: docker push "tarampampam/mikrotik-hosts-parser:${version/[vV]/}" diff --git a/CHANGELOG.md b/CHANGELOG.md index caedf310..491e7c63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver]. +## v3.0.2 + +### Changed + +- Docker image supports argument with application version value +- Docker image builds using GitHub Actions (not hub.docker.com) + ## v3.0.1 ### Fixed diff --git a/Dockerfile b/Dockerfile index 33246cff..e47a43c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,13 @@ # Image page: FROM golang:1.13-alpine as builder +# can be passed with any prefix (like `v1.2.3@GITHASH`) +# e.g.: `docker build --build-arg "APP_VERSION=v1.2.3@GITHASH" .` +ARG APP_VERSION="undefined@docker" + RUN set -x \ - # Install git + SSL ca certificates (ca-certificates is required to call HTTPS endpoints) - && apk add --no-cache git ca-certificates \ + # SSL ca certificates (ca-certificates is required to call HTTPS endpoints) + && apk add --no-cache ca-certificates \ && update-ca-certificates WORKDIR /src @@ -20,9 +24,7 @@ RUN set -x \ COPY . /src RUN set -x \ - # @todo: replace git-depencency with build arguments - && export version=`git symbolic-ref -q --short HEAD || git describe --tags --exact-match`@`git rev-parse --short HEAD` \ - && GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X mikrotik-hosts-parser/version.version=${version}" . \ + && GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X mikrotik-hosts-parser/version.version=${APP_VERSION}" . \ && ./mikrotik-hosts-parser version \ && ./mikrotik-hosts-parser -h diff --git a/README.md b/README.md index 868483b0..6be7e347 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,10 @@ For local application starting using binary file, you must compile application _ ```bash $ ./mikrotik-hosts-parser serve \ - --config=./serve.yml \ - --listen=0.0.0.0 \ - --port=8080 \ - --resources-dir=./public + --config ./serve.yml \ + --listen 0.0.0.0 \ + --port 8080 \ + --resources-dir ./public ``` This command will start HTTP server using configuration from `./serve.yml` on port `8080` and use directory `./public` for serving static files. Configuration file well-documented, so, feel free to change any settings on your choice! @@ -47,12 +47,10 @@ Special endpoint `/script/source?sources_urls=...` generates RouterOS-based scri Just execute in your terminal: ```bash -$ docker run --rm \ - -p 8080:8080 \ - tarampampam/mikrotik-hosts-parser +$ docker run --rm -p 8080:8080/tcp tarampampam/mikrotik-hosts-parser:X.X.X ``` -You can use `latest` or `X.X.X` as image tag _(application version)_. All available docker image tags can be [found here][link_docker_hub_tags]. +Where `X.X.X` is image tag _(application version)_. All available docker image tags can be [found here][link_docker_hub_tags]. ## Demo