Skip to content
Snippets Groups Projects
Commit e0363236 authored by masi9606's avatar masi9606
Browse files

Merge branch 't4-build-publish-container' into 'main'

update ci/cd pipeline to build and push docker images

See merge request !1
parents 3b1bd651 7192c368
No related branches found
No related tags found
3 merge requests!4build new image with ubuntu,!2update ci/cd pipeline to build and push docker images,!1update ci/cd pipeline to build and push docker images
Pipeline #63538 passed
......@@ -4,54 +4,50 @@ workflow:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || ($CI_PIPELINE_SOURCE == "push" && ($CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "prod"))
when: always
- when: never
variables:
version: 0.0.$CI_PIPELINE_IID
stages:
- test
- build
- publish
test_job:
stage: test
image: public.ecr.aws/docker/library/golang:1.21
script:
- go get -t ./...
- go test -race -v ./...
build_job:
stage: build
rules:
- if: $CI_COMMIT_REF_NAME =~ /prod/
when: always
image: public.ecr.aws/docker/library/golang:1.21
parallel:
matrix:
- GOOS:
- linux
- darwin
- windows
GOARCH:
- amd64
- arm64
script: |
go build -o webservice_${GOOS}_${GOARCH}.bin ./*.go
GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build -o artifact.bin ./*.go
artifacts:
paths:
- webservice_${GOOS}_${GOARCH}.bin
- artifact.bin
expire_in: 5 min
publish_job:
stage: publish
rules:
- if: $CI_COMMIT_REF_NAME =~ /prod/
when: always
image: public.ecr.aws/docker/library/alpine:latest
image: docker:latest
services:
- docker:dind
tags:
- docker-privileged
dependencies:
- build_job
before_script:
- apk add --no-cache curl
script: >
for file in $(ls webservice_*); do
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" \
--upload-file "./$file" \
"$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/generic/artifacts/$version/$file"
done
script:
- docker build -t $CI_REGISTRY_IMAGE:$version -f Containerfile .
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE:$version
after_script:
- docker logout $CI_REGISTRY
# syntax=docker/dockerfile:1
FROM scratch
COPY artifact.bin /artifact.bin
ENV HOST=0.0.0.0
ENV PORT=8080
EXPOSE 8080
CMD ["/artifact.bin"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment