From 18b9d4354516e9e34fba98f691dbfdb9d5847953 Mon Sep 17 00:00:00 2001 From: Kent Daleng Date: Tue, 17 Aug 2021 13:57:06 +0200 Subject: [PATCH] use ci --- .github/workflows/deploy.yml | 36 ++++++++++++++++++++++++++++++++++++ .gitignore | 1 + .nais/nais.yml | 9 +++++++++ Dockerfile | 15 +++++++++++++++ README.md | 3 +++ cmd/wonderwall/main.go | 10 ++++++++++ version.sh | 7 +++++++ 7 files changed, 81 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 .gitignore create mode 100644 .nais/nais.yml create mode 100644 Dockerfile create mode 100755 version.sh diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..ecd233f --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,36 @@ +name: Build wonderwall + +on: [push] + +env: + image_base: ghcr.io/${{ github.repository }} + +jobs: + build-and-deploy: + name: Build, push and deploy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Docker login + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: docker login ghcr.io -u ${GITHUB_REPOSITORY} -p ${GITHUB_TOKEN} + - name: Set version + run: | + echo "VERSION=$(./version.sh)" >> $GITHUB_ENV + - name: Build Docker image + run: | + docker build . --tag ${image_base}:${{ env.VERSION }} --tag ${image_base}:latest + - name: Push versioned docker image + run: | + docker push ${image_base}:${{ env.VERSION }} + - name: Push latest docker image + if: github.ref == 'refs/heads/master' + run: docker push ${image_base}:latest + - uses: nais/deploy/actions/deploy@v1 + if: github.ref == 'refs/heads/master' + env: + APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} + CLUSTER: dev-gcp + RESOURCE: .nais/nais.yml + VAR: image=${image_base}:${{ env.VERSION }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/ diff --git a/.nais/nais.yml b/.nais/nais.yml new file mode 100644 index 0000000..4ce937c --- /dev/null +++ b/.nais/nais.yml @@ -0,0 +1,9 @@ +apiVersion: nais.io/v1alpha1 +kind: Application +metadata: + name: wonderwall + namespace: aura + labels: + team: aura +spec: + image: {{ image }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..63adc47 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.16-alpine as builder +RUN apk add --no-cache git make curl +ENV GOOS=linux +ENV CGO_ENABLED=0 +ENV GO111MODULE=on +COPY . /src +WORKDIR /src +RUN make test +RUN make alpine + +FROM alpine:3 +RUN export PATH=$PATH:/app +WORKDIR /app +COPY --from=builder /src/bin/wonderwall /app/wonderwall +ENTRYPOINT ["/app/wonderwall"] diff --git a/README.md b/README.md index b611268..3052c54 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ # wonderwall + +![anyway here's wonderwall](https://i.imgur.com/NhRLEej.png) + diff --git a/cmd/wonderwall/main.go b/cmd/wonderwall/main.go index 06ab7d0..40603f7 100644 --- a/cmd/wonderwall/main.go +++ b/cmd/wonderwall/main.go @@ -1 +1,11 @@ package main + +import ( + "fmt" + "time" +) + +func main() { + fmt.Println("Sleeping for a while") + time.Sleep(time.Hour * 12) +} diff --git a/version.sh b/version.sh new file mode 100755 index 0000000..b868dc3 --- /dev/null +++ b/version.sh @@ -0,0 +1,7 @@ +#!/bin/sh +dirty="" +test -z "$(git ls-files --exclude-standard --others)" +if [ $? -ne 0 ]; then + dirty="-dirty" +fi +echo $(date "+%Y-%m-%d")-$(git --no-pager log -1 --pretty=%h)${dirty}