refactored to use the latest stdlib and cloudlib #7
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: build_router | |
on: | |
push: | |
branches: [develop] | |
env: | |
CONTEXT_DIR: cmd/router | |
CONTAINER_IMAGE: router | |
CONTAINER_VERSION: 0.2.2 | |
REPOSITORY: ${{ secrets.REPOSITORY }} | |
REPOSITORY_HOST: ${{ secrets.REPOSITORY_HOST }} | |
GITHUB_SHA: ${{ github.sha }} | |
jobs: | |
build_router: | |
runs-on: ubuntu-latest | |
steps: | |
- name: setup go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ^1.19 | |
id: go | |
- name: checkout code | |
uses: actions/checkout@v3 | |
- name: authenticate gcloud SDK | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: "${{ secrets.GCP_SA_KEY }}" | |
id: auth | |
- name: setup gcloud SDK | |
uses: google-github-actions/setup-gcloud@v1 | |
- run: gcloud auth configure-docker $REPOSITORY_HOST | |
- name: build the service | |
run: | | |
cd $CONTEXT_DIR | |
go get -v -t -d ./... | |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o svc main.go | |
- name: build the container | |
run: | | |
cd $CONTEXT_DIR | |
docker build --rm=true -t "$REPOSITORY_HOST"/"$REPOSITORY"/"$CONTAINER_IMAGE":"$GITHUB_SHA" . | |
- name: push the container | |
run: | | |
docker push $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:$GITHUB_SHA | |
docker tag $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:$GITHUB_SHA $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:latest | |
docker tag $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:$GITHUB_SHA $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:$CONTAINER_VERSION | |
docker push $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:latest | |
docker push $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:$CONTAINER_VERSION |