Skip to content

Commit

Permalink
ci: Add ci image build job
Browse files Browse the repository at this point in the history
  • Loading branch information
cluttrdev committed Nov 13, 2024
1 parent 70428f3 commit a40d159
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .gitlab/gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@ default:
image: golang:${GOVERSION}
tags: [ $GITLAB_CI_DEFAULT_TAGS ]

ci-image:
stage: .pre
rules:
- when: manual
allow_failure: true
image: docker:latest
services:
- name: docker:dind
alias: docker
variables:
GOVERSION: 1.22
before_script:
- echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY --username $CI_REGISTRY_USER --password-stdin
script:
- | # Set up image name and tag
export IMAGE=${CI_REGISTRY_IMAGE}/golang-ci
export TAG=$(TZ=UTC git show --no-patch --format='%cd' --date='format-local:%Y%m%d%H%M%S' $CI_COMMIT_SHA)-${CI_COMMIT_SHA::12}
- | # Build image
docker build \
--file .gitlab/images/golang-ci/Dockerfile \
--build-arg GOVERSION \
--tag "${IMAGE}:${TAG}" \
.gitlab/images/golang-ci/
- | # Push image
docker push ${IMAGE}:${TAG}
download:
stage: .pre
script:
Expand Down
32 changes: 32 additions & 0 deletions .gitlab/images/golang-ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG GOVERSION=1.22
FROM golang:${GOVERSION}-alpine

# add system requirements
RUN apk add --no-cache \
ca-certificates \
curl \
findutils \
just \
git \
tar \
zip

# add ci tools

# golangci-lint
ARG golangci_lint_VERSION=v1.62.0
RUN curl -sSfL https://github.com/golangci/golangci-lint/releases/download/${golangci_lint_VERSION}/golangci-lint-${golangci_lint_VERSION#v}-linux-amd64.tar.gz \
-o /tmp/golangci-lint.tar.gz \
&& tar -zxof /tmp/golangci-lint.tar.gz \
--strip-components=1 \
-C /go/bin/ \
golangci-lint-${golangci_lint_VERSION#v}-linux-amd64/golangci-lint

# gotestsum
ARG gotestsum_VERSION=v1.12.0
RUN curl -sSfL https://github.com/gotestyourself/gotestsum/releases/download/${gotestsum_VERSION}/gotestsum_${gotestsum_VERSION#v}_linux_amd64.tar.gz \
-o /tmp/gotestsum.tar.gz \
&& tar -zxof /tmp/gotestsum.tar.gz \
-C /go/bin/ \
gotestsum

20 changes: 20 additions & 0 deletions .gitlab/images/jobs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

ci-image:
manual: true
stage: .pre
image: docker:stable
services:
- name: docker:stable-dind
alias: docker
variables:
GOVERSION: 1.22

script:
- |
TAG=${CI_COMMIT_TIMESTAMP//[^0-9]/}-${CI_COMMIT_SHA::12} \
docker build \
--file .gitlab/images/golang-ci/Dockerfile \
--build-arg GOVERSION \
--tag "golang-ci:${TAG} \
.gitlab/images/golang-ci/

0 comments on commit a40d159

Please sign in to comment.