mirror of
https://codeberg.org/Codeberg-CI/examples.git
synced 2025-09-08 19:35:00 -04:00
Adds some examples to build golang projects (#3)
I added some examples to - use the CI to build golang projects - build and publish a 'latest' tagged docker container to DockerHub - build and publish a version tagged docker container from a version tag to DockerHub Co-authored-by: JohnWalkerx <johnwalkerx@mailbox.org> Reviewed-on: https://codeberg.org/Codeberg-CI/examples/pulls/3 Co-authored-by: JohnWalkerx <johnwalkerx@noreply.codeberg.org> Co-committed-by: JohnWalkerx <johnwalkerx@noreply.codeberg.org>
This commit is contained in:
parent
9695398116
commit
28d812b95f
@ -8,6 +8,8 @@ Pull requests are accepted/welcome.
|
||||
| Link | Language | Build System | Comments |
|
||||
| :-- | :-- | :-- | :-- |
|
||||
| [C/make.yml](C/make.yml) | C | Make | Simple ci for building a Make based C project |
|
||||
| [golang/build.yml](golang/build.yml) | golang | golang | Simple ci for building and test a Go project |
|
||||
| [golang/build-docker.yml](golang/build-docker.yml) | golang | golang / kaniko | CI to build golang project and build various docker container and publish them on DockerHub |
|
||||
|
||||
# More:
|
||||
https://codeberg.org/explore/repos?q=woodpecker-ci&topic=1
|
||||
|
17
golang/Dockerfile
Normal file
17
golang/Dockerfile
Normal file
@ -0,0 +1,17 @@
|
||||
# Replace 'APPLICATIONNAME' with the name of your golang project
|
||||
|
||||
FROM golang:1.17 AS certs
|
||||
|
||||
FROM scratch
|
||||
|
||||
# copy certs from golang:1.17 image
|
||||
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
# Copy prebuild Go binary into container
|
||||
COPY ./APPLICATIONNAME /APPLICATIONNAME
|
||||
|
||||
# Uncomment and ajust if golang application exposes an port
|
||||
#EXPOSE 3000
|
||||
|
||||
# Run application
|
||||
CMD ["/APPLICATIONNAME"]
|
64
golang/build-docker.yml
Normal file
64
golang/build-docker.yml
Normal file
@ -0,0 +1,64 @@
|
||||
pipeline:
|
||||
# Builds your Go application
|
||||
build:
|
||||
# Set your preferred Go version:
|
||||
image: golang:1.17
|
||||
environment:
|
||||
# Needed if you want to cross-compile and package the binary in a container.
|
||||
- CGO_ENABLED=0
|
||||
# Select your target OS:
|
||||
- GOOS=linux
|
||||
# Select your target architecture:
|
||||
- GOARCH=amd64
|
||||
commands:
|
||||
- go get
|
||||
- go build
|
||||
|
||||
# Runs a dryrun to build the docker container
|
||||
dryrun-docker:
|
||||
image: plugins/kaniko
|
||||
settings:
|
||||
repo: DOCKERUSERNAME/DOCKERHUBREPO
|
||||
tags: test
|
||||
dockerfile: Dockerfile
|
||||
# Just builds the container without a push to DockerHub.
|
||||
no_push: true
|
||||
when:
|
||||
event: pull_request
|
||||
|
||||
# Builds and publish a docker container to DockerHub from the main-branch
|
||||
publish-docker-latest:
|
||||
image: plugins/kaniko
|
||||
settings:
|
||||
repo: DOCKERUSERNAME/DOCKERHUBREPO
|
||||
tags: latest
|
||||
dockerfile: Dockerfile
|
||||
username:
|
||||
# Secret 'docker_username' needs to be set in the CI settings
|
||||
from_secret: docker_username
|
||||
password:
|
||||
# Secret 'docker_password' needs to be set in the CI settings
|
||||
from_secret: docker_password
|
||||
when:
|
||||
# Push new version of tag latest if new push on main-branch
|
||||
event: push
|
||||
branch: main
|
||||
|
||||
# Builds and publishes a docker container of a tag
|
||||
publish-docker-tag:
|
||||
image: plugins/kaniko
|
||||
settings:
|
||||
repo: DOCKERUSERNAME/DOCKERHUBREPO
|
||||
# Uses the tag from git for the container tag
|
||||
tags: ${CI_COMMIT_TAG}
|
||||
dockerfile: Dockerfile
|
||||
username:
|
||||
# Secret 'docker_username' needs to be set in the CI settings
|
||||
from_secret: docker_username
|
||||
password:
|
||||
# Secret 'docker_password' needs to be set in the CI settings
|
||||
from_secret: docker_password
|
||||
when:
|
||||
# Push new version when version tag is created
|
||||
event: tag
|
||||
tag: v*
|
8
golang/build.yml
Normal file
8
golang/build.yml
Normal file
@ -0,0 +1,8 @@
|
||||
pipeline:
|
||||
build:
|
||||
image: golang:1.17
|
||||
commands:
|
||||
- go get
|
||||
- go build
|
||||
# Optional: Run go tests
|
||||
- go test
|
Loading…
x
Reference in New Issue
Block a user