mirror of
https://github.com/stefanprodan/podinfo.git
synced 2026-08-28 17:57:16 +00:00
Generate Github actions CI pipeline
- add custom Dockerfile - use GitHub actions env vars as docker build args - remove .gh from Makefile and Dockerfile in destination project
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
FROM docker:stable
|
||||
|
||||
LABEL "name"="Docker tag and push action"
|
||||
LABEL "maintainer"="Stefan Prodan <support@gweave.works>"
|
||||
LABEL "maintainer"="Stefan Prodan <support@weave.works>"
|
||||
LABEL "version"="1.0.0"
|
||||
|
||||
LABEL "com.github.actions.icon"="terminal"
|
||||
LABEL "com.github.actions.color"="gray-dark"
|
||||
LABEL "com.github.actions.icon"="package"
|
||||
LABEL "com.github.actions.color"="green"
|
||||
LABEL "com.github.actions.name"="Docker Publish"
|
||||
LABEL "com.github.actions.description"="This is an Action to run docker tag and push commands."
|
||||
|
||||
RUN apk update \
|
||||
&& apk add --no-cache ca-certificates bash git curl \
|
||||
&& (apk info | xargs -n1 -I{} apk --quiet add {}-doc); true \
|
||||
RUN apk add --no-cache ca-certificates bash git curl \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
@@ -4,8 +4,6 @@ set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
echo "Starting tag and push for image ${DOCKER_IMAGE} release ${GITHUB_REF}"
|
||||
|
||||
DOCKER_TAG="latest"
|
||||
if [[ "${GITHUB_REF}" == "refs/tags"* ]]; then
|
||||
DOCKER_TAG=$(echo ${GITHUB_REF} | rev | cut -d/ -f1 | rev)
|
||||
@@ -13,7 +11,14 @@ else
|
||||
DOCKER_TAG=$(echo ${GITHUB_REF} | rev | cut -d/ -f1 | rev)-$(echo ${GITHUB_SHA} | head -c7)
|
||||
fi
|
||||
|
||||
docker tag app ${DOCKER_IMAGE}:${DOCKER_TAG}
|
||||
docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
|
||||
if [[ "$1" == "build" ]]; then
|
||||
docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} \
|
||||
--build-arg REPOSITORY=${GITHUB_REPOSITORY} \
|
||||
--build-arg SHA=${GITHUB_SHA} -f $2 .
|
||||
fi
|
||||
|
||||
if [[ "$1" == "push" ]]; then
|
||||
docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
|
||||
fi
|
||||
|
||||
echo "Docker image pushed to ${DOCKER_IMAGE}:${DOCKER_TAG}"
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
FROM golang:1.10
|
||||
|
||||
LABEL "name"="golang tools action"
|
||||
LABEL "maintainer"="Stefan Prodan <support@gweave.works>"
|
||||
LABEL "maintainer"="Stefan Prodan <support@weave.works>"
|
||||
LABEL "version"="1.0.0"
|
||||
|
||||
LABEL "com.github.actions.icon"="code"
|
||||
LABEL "com.github.actions.color"="gray-dark"
|
||||
LABEL "com.github.actions.color"="green-dark"
|
||||
LABEL "com.github.actions.name"="Go Tools"
|
||||
LABEL "com.github.actions.description"="This is an Action to run go and dep commands."
|
||||
|
||||
@@ -10,7 +10,7 @@ APP_DIR="/go/src/github.com/${GITHUB_REPOSITORY}/"
|
||||
mkdir -p ${APP_DIR} && cp -r ./ ${APP_DIR} && cd ${APP_DIR}
|
||||
|
||||
if [[ "$1" == "fmt" ]]; then
|
||||
echo "Running gofmt"
|
||||
echo "Running go fmt"
|
||||
files=$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*") 2>&1)
|
||||
if [ "$files" ]; then
|
||||
echo "These files did not pass the gofmt check:"
|
||||
@@ -21,6 +21,6 @@ fi
|
||||
|
||||
if [[ "$1" == "test" ]]; then
|
||||
echo "Running go test"
|
||||
go test $(go list ./... | grep -v /vendor/) -cover
|
||||
go test $(go list ./... | grep -v /vendor/) -race -coverprofile=coverage.txt -covermode=atomic
|
||||
cat coverage.txt
|
||||
fi
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
workflow "Publish container" {
|
||||
on = "push"
|
||||
resolves = ["Docker tag and push"]
|
||||
resolves = ["Push"]
|
||||
}
|
||||
|
||||
action "Lint" {
|
||||
@@ -16,18 +16,20 @@ action "Test" {
|
||||
|
||||
action "Build" {
|
||||
needs = ["Test"]
|
||||
uses = "actions/docker/cli@master"
|
||||
args = "build -t app -f Dockerfile.ci ."
|
||||
uses = "./.github/actions/docker"
|
||||
secrets = ["DOCKER_IMAGE"]
|
||||
args = ["build", "Dockerfile.gh"]
|
||||
}
|
||||
|
||||
action "Docker login" {
|
||||
action "Login" {
|
||||
needs = ["Build"]
|
||||
uses = "actions/docker/login@master"
|
||||
secrets = ["DOCKER_USERNAME", "DOCKER_PASSWORD"]
|
||||
}
|
||||
|
||||
action "Docker tag and push" {
|
||||
needs = ["Docker login"]
|
||||
action "Push" {
|
||||
needs = ["Login"]
|
||||
uses = "./.github/actions/docker"
|
||||
secrets = ["DOCKER_IMAGE"]
|
||||
args = "push"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user