fix proxy path (#55) #128
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: Backend CI and CD | |
on: | |
push: | |
paths: | |
- .github/** | |
- backend/** | |
pull_request: | |
paths: | |
- .github/** | |
- backend/** | |
defaults: | |
run: | |
working-directory: ./backend | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: backend | |
jobs: | |
ci: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.23.x' | |
- name: Run unit tests | |
run: | | |
go test ./... -v -race -cover | |
- name: Provide image name and version | |
run: | | |
IMAGE_ID=$(echo $REGISTRY/${{ github.repository_owner }}/$IMAGE_NAME | tr '[A-Z]' '[a-z]') | |
IMAGE_VERSION=${{ github.sha }} | |
echo "IMAGE_ID=$IMAGE_ID" >> "$GITHUB_ENV" | |
echo "IMAGE_VERSION=$IMAGE_VERSION" >> "$GITHUB_ENV" | |
- name: Build image | |
run: | | |
docker build . --file Dockerfile --target production --tag $IMAGE_ID:$IMAGE_VERSION --tag $IMAGE_ID:latest | |
cd: | |
runs-on: ubuntu-latest | |
if: ${{ format('refs/heads/{0}', github.event.repository.default_branch) == github.ref }} | |
permissions: | |
packages: write | |
contents: read | |
needs: | |
- ci | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Provide image name and version | |
run: | | |
IMAGE_ID=$(echo $REGISTRY/${{ github.repository_owner }}/$IMAGE_NAME | tr '[A-Z]' '[a-z]') | |
IMAGE_VERSION=${{ github.sha }} | |
echo "IMAGE_ID=$IMAGE_ID" >> "$GITHUB_ENV" | |
echo "IMAGE_VERSION=$IMAGE_VERSION" >> "$GITHUB_ENV" | |
- name: Build image | |
run: | | |
docker build . --file Dockerfile --target production --tag $IMAGE_ID:$IMAGE_VERSION --tag $IMAGE_ID:latest | |
- name: Log in to registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Push image | |
run: | | |
docker push $IMAGE_ID:$IMAGE_VERSION | |
docker push $IMAGE_ID:latest |