docker publish를 위한 ci pipeline 구성 #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Publish | |
on: | |
push: | |
branches: | |
- master | |
- feature | |
pull_request: | |
branches: | |
- master | |
- feature | |
jobs: | |
test: | |
strategy: | |
# Default is true, cancels jobs for other platforms in the matrix if one fails | |
fail-fast: true | |
matrix: | |
os: [ ubuntu-latest, macos-latest, windows-latest ] | |
go: [ '1.21' ] | |
include: | |
# Set the minimum Go patch version for the given Go minor | |
# Usable via ${{ matrix.GO_SEMVER }} | |
- go: '1.21' | |
GO_SEMVER: '~1.21.1' | |
- os: ubuntu-latest | |
SUCCESS: 0 | |
- os: macos-latest | |
SUCCESS: 0 | |
- os: windows-latest | |
SUCCESS: 'True' | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Install Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ matrix.GO_SEMVER }} | |
check-latest: true | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install test and coverage analysis tools | |
run: | | |
go install github.com/axw/gocov/gocov@latest | |
go install github.com/AlekSi/gocov-xml@latest | |
- name: Print Go version and environment | |
id: vars | |
run: | | |
printf "Using go at: $(which go)\n" | |
printf "Go version: $(go version)\n" | |
printf "\n\nGo environment:\n\n" | |
go env | |
printf "\n\nSystem environment:\n\n" | |
env | |
printf "Git version: $(git version)\n\n" | |
# Calculate the short SHA1 hash of the git commit | |
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- name: Get dependencies | |
run: | | |
go get -v -t -d ./... | |
- name: Build Aviator | |
working-directory: ./cmd | |
env: | |
CGO_ENABLED: 0 | |
run: | | |
go build -trimpath -ldflags="-w -s" -v | |
- name: Run tests | |
# Allow the job to continue even if the tests fail, so we can publish the report separately | |
# https://stackoverflow.com/questions/57850553/github-actions-check-steps-status | |
id: step_test | |
continue-on-error: true | |
run: | | |
go test ./... -v -covermode count -coverprofile test-coverage.out | tee test_output_unit_temp.log | |
go test -v -coverprofile="cover-profile.out" -short -race ./... | |
- name: Prepare coverage reports | |
run: | | |
mkdir coverage | |
gocov convert cover-profile.out > coverage/coverage.json | |
# Because Windows doesn't work with input redirection like *nix, but output redirection works. | |
(cat ./coverage/coverage.json | gocov-xml) > coverage/coverage.xml | |
- name: Archive code coverage results | |
uses: actions/upload-artifact@v3 | |
with: | |
name: code-coverage-report | |
path: coverage/coverage.xml | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Docker meta | |
id: docker_meta | |
uses: docker/metadata-action@v4 | |
with: | |
# list of Docker images to use as base name for tags | |
images: | | |
cloud-club/aviator-services | |
# generate Docker tags based on the following events/attributes | |
tags: | | |
type=schedule | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
type=sha | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
labels: ${{ steps.docker_meta.outputs.labels }} |