feat: Add action script
All checks were successful
Build Docker / BuildSite (push) Successful in 2m25s

This commit is contained in:
Nathan Woodburn 2024-06-17 15:53:53 +10:00
parent 9c5189071a
commit 842f693bc7
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 61 additions and 0 deletions

View File

@ -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

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
main

13
Dockerfile Normal file
View File

@ -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"]