Skip to content

Commit

Permalink
👷 Update build system.
Browse files Browse the repository at this point in the history
  • Loading branch information
transnano committed Oct 31, 2020
1 parent c3068b0 commit a1cc005
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 126 deletions.
86 changes: 12 additions & 74 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,80 +1,18 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.137.0/containers/go/.devcontainer/base.Dockerfile
ARG VARIANT="1"
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT}

FROM golang:1.15.3
# [Optional] Install a version of Node.js using nvm for front end dev
ARG INSTALL_NODE="true"
ARG NODE_VERSION="lts/*"
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# This Dockerfile adds a non-root user with sudo access. Update the “remoteUser” property in
# devcontainer.json to use it. More info: https://aka.ms/vscode-remote/containers/non-root-user.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Options for common setup script - SHA generated on release
ARG INSTALL_ZSH="true"
ARG UPGRADE_PACKAGES="false"
ARG COMMON_SCRIPT_SOURCE="https://raw.githubusercontent.com/microsoft/vscode-dev-containers/master/script-library/common-debian.sh"
ARG COMMON_SCRIPT_SHA="dev-mode"

# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
RUN apt-get update \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends curl ca-certificates 2>&1 \
&& curl -sSL ${COMMON_SCRIPT_SOURCE} -o /tmp/common-setup.sh \
&& ([ "${COMMON_SCRIPT_SHA}" = "dev-mode" ] || (echo "${COMMON_SCRIPT_SHA} /tmp/common-setup.sh" | sha256sum -c -)) \
&& /bin/bash /tmp/common-setup.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" \
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Install Go tools
ARG GO_TOOLS_WITH_MODULES="\
golang.org/x/tools/gopls \
honnef.co/go/tools/... \
golang.org/x/tools/cmd/gorename \
golang.org/x/tools/cmd/goimports \
golang.org/x/tools/cmd/guru \
golang.org/x/lint/golint \
github.com/mdempsky/gocode \
github.com/cweill/gotests/... \
github.com/haya14busa/goplay/cmd/goplay \
github.com/sqs/goreturns \
github.com/josharian/impl \
github.com/davidrjenni/reftools/cmd/fillstruct \
github.com/uudashr/gopkgs/v2/cmd/gopkgs \
github.com/ramya-rao-a/go-outline \
github.com/acroca/go-symbols \
github.com/godoctor/godoctor \
github.com/rogpeppe/godef \
github.com/zmb3/gogetdoc \
github.com/fatih/gomodifytags \
github.com/mgechev/revive \
github.com/go-delve/delve/cmd/dlv"
RUN mkdir -p /tmp/gotools \
&& cd /tmp/gotools \
&& export GOPATH=/tmp/gotools \
# Go tools w/module support
&& export GO111MODULE=on \
&& (echo "${GO_TOOLS_WITH_MODULES}" | xargs -n 1 go get -x )2>&1 \
# gocode-gomod
&& export GO111MODULE=auto \
&& go get -x -d github.com/stamblerre/gocode 2>&1 \
&& go build -o gocode-gomod github.com/stamblerre/gocode \
# golangci-lint
&& curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin 2>&1 \
# Move Go tools into path and clean up
&& mv /tmp/gotools/bin/* /usr/local/bin/ \
&& mv gocode-gomod /usr/local/bin/ \
&& rm -rf /tmp/gotools

ENV GO111MODULE=auto
# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment the next line to use go get to install anything else you need
# RUN go get -x <your-dependency-or-tool>

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update \
# && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
33 changes: 22 additions & 11 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.137.0/containers/go
{
"name": "Go",
"build": {
"dockerfile": "Dockerfile"
"dockerfile": "Dockerfile",
"args": {
// Update the VARIANT arg to pick a version of Go: 1, 1.15, 1.14
"VARIANT": "1",
// Options
"INSTALL_NODE": "false",
"NODE_VERSION": "lts/*"
}
},
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],

"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/zsh",
"go.useGoProxyToCheckForToolUpdates": false,
"go.gopath": "/go",
"go.inferGopath": true,
"go.useLanguageServer": true
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"Compulim.vscode-clock",
Expand All @@ -23,15 +34,15 @@
"shardulm94.trailing-spaces",
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
"donjayamanne.githistory"
"donjayamanne.githistory",
"hediet.vscode-drawio"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [9000],

"forwardPorts": [
9000
],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "go version",

// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
}
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: 'Code Scanning(CodeQL)'

on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]
schedule:
- cron: '0 5 * * 5'

Expand Down
105 changes: 71 additions & 34 deletions .github/workflows/docker-hub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,84 @@ on:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
docker:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
- name: Checkout
uses: actions/checkout@v2
- name: Push to Docker Hub
uses: docker/build-push-action@v2

- name: Prepare
id: prep
run: |
DOCKER_IMAGE=${{ github.repository }}
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
fi
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
TAGS="docker.io/$TAGS,ghcr.io/$TAGS"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,docker.io/${DOCKER_IMAGE}:latest,ghcr.io/${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=tags::${TAGS}
echo ::set-output name=BUILD_DATE::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=VERSION::${VERSION}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: transnano/proftpd-exporter
tag_with_ref: true
env:
DOCKER_BUILDKIT: 1
- name: Push to GitHub Packages
uses: docker/build-push-action@v2
platforms: all

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

- name: Cache Docker layers
uses: actions/cache@v2
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
repository: ${{ github.repository }}/proftpd-exporter
tag_with_ref: true
env:
DOCKER_BUILDKIT: 1
- name: Push to Docker Hub(latest)
uses: docker/build-push-action@v2
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: transnano/proftpd-exporter
tags: latest
env:
DOCKER_BUILDKIT: 1
- name: Push to GitHub Packages(latest)

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
repository: ${{ github.repository }}/proftpd-exporter
tags: latest
env:
DOCKER_BUILDKIT: 1
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/386,linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ steps.prep.outputs.VERSION }}
org.opencontainers.image.created=${{ steps.prep.outputs.BUILD_DATE }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
7 changes: 3 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ builds:
- -s -w
- -X github.com/prometheus/common/version.Version={{.Version}}
- -X github.com/prometheus/common/version.BuildDate={{.Date}}
- -X github.com/prometheus/common/version.Branch=master
- -X github.com/prometheus/common/version.Branch=main
- -X github.com/prometheus/common/version.Revision={{.ShortCommit}}
- -X github.com/prometheus/common/version.BuildUser=transnano
env:
- CGO_ENABLED=0
archives:
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
- name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
replacements:
darwin: darwin
linux: linux
Expand All @@ -31,8 +31,7 @@ archives:
release:
prerelease: auto
nfpms:
-
id: proftpd-exporter-nfpms
- id: proftpd-exporter-nfpms
package_name: proftpd-exporter
homepage: https://github.com/transnano/proftpd_exporter
maintainer: Transnano <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ COPY . .
RUN go build -o proftpd-exporter -ldflags "-s -w \
-X github.com/prometheus/common/version.Version=$(git describe --tags --abbrev=0) \
-X github.com/prometheus/common/version.BuildDate=$(date +%FT%T%z) \
-X github.com/prometheus/common/version.Branch=master \
-X github.com/prometheus/common/version.Branch=main \
-X github.com/prometheus/common/version.Revision=$(git rev-parse --short HEAD) \
-X github.com/prometheus/common/version.BuildUser=transnano"

Expand Down

0 comments on commit a1cc005

Please sign in to comment.