From 842f693bc7da878f33b439eb5f686a64d277828c Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Mon, 17 Jun 2024 15:53:53 +1000 Subject: [PATCH] feat: Add action script --- .gitea/workflows/build.yml | 46 ++++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ Dockerfile | 13 +++++++++++ 3 files changed, 61 insertions(+) create mode 100644 .gitea/workflows/build.yml create mode 100644 .gitignore create mode 100644 Dockerfile diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..489226c --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,46 @@ +name: Build Docker +run-name: Build Docker Image +on: + push: + +jobs: + BuildSite: + runs-on: [ubuntu-latest, amd] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install Docker + run : | + apt-get install ca-certificates curl gnupg + install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + chmod a+r /etc/apt/keyrings/docker.gpg + echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null + apt-get update + apt-get install docker-ce-cli -y + - name: Build Docker image + run : | + echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" + tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + tag=${tag//\//-} + tag_num=${GITHUB_RUN_NUMBER} + echo "tag_num=$tag_num" + + if [[ "$tag" == "main" ]]; then + tag="latest" + else + tag_num="${tag}-${tag_num}" + fi + + echo "tag=$tag" + echo "tag_num=$tag_num" + echo "Git repo name: $GITHUB_REPOSITORY" + + + + docker build -t go-webserver-template:$tag_num . + docker tag go-webserver-template:$tag_num git.woodburn.au/nathanwoodburn/go-webserver-template:$tag_num + docker push git.woodburn.au/nathanwoodburn/go-webserver-template:$tag_num + docker tag go-webserver-template:$tag_num git.woodburn.au/nathanwoodburn/go-webserver-template:$tag + docker push git.woodburn.au/nathanwoodburn/go-webserver-template:$tag \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6dd513d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +main diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8654c7a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +# syntax=docker/dockerfile:1 +FROM golang:1.19 + +# Set destination for COPY +WORKDIR /app + +COPY main.go ./ +COPY templates ./templates/ +RUN go build main.go +EXPOSE 3000 + +# Run +CMD ["./main"] \ No newline at end of file