Skip to content

docker-build-push-latest-dev #64

docker-build-push-latest-dev

docker-build-push-latest-dev #64

name: docker-build-push-latest-dev
on:
workflow_dispatch:
push:
branches:
- latest-dev
jobs:
build-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout frontend code
uses: actions/checkout@v3
with:
repository: dongshull/Docker-Copilot-React
path: './frontend'
ref: 'master'
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: |
frontend/package-lock.json
frontend/package.json
- name: Build Frontend
run: |
cd frontend
npm ci
npm run build
- name: Upload Frontend Artifacts
uses: actions/upload-artifact@v4
with:
name: my-artifact-front-dist
path: frontend/dist
build-backend:
needs: [ build-frontend ]
runs-on: ubuntu-latest
strategy:
matrix:
arch: [ amd64, arm64 ]
steps:
- name: Checkout code back end
uses: actions/checkout@v3
- name: Download Frontend Artifacts
uses: actions/download-artifact@v4
with:
pattern: my-artifact-front-*
merge-multiple: true
path: front
- run: ls -R front
- name: Get version from file
id: get_version
run: |
echo "version=$(cat version)" >> $GITHUB_ENV
- name: Cache Go Modules
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/msaber-back/pkg/mod
key: go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: |
go-mod-
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23.4'
cache: false
- name: Build for ${{ matrix.arch }}
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=${{ matrix.arch }} go build -a --trimpath -ldflags="-w -s -X 'github.com/onlyLTY/dockerCopilot/internal/config.Version=${{ env.version }}' -X 'github.com/onlyLTY/dockerCopilot/internal/config.BuildDate=$(date)'" -o dist/linux/${{ matrix.arch }}/dockerCopilot .
- name: Prepare Files
run: |
mkdir -p dc-back-${{ matrix.arch }}
cp -r dist dc-back-${{ matrix.arch }}/dist
cp -r etc dc-back-${{ matrix.arch }}/etc
- name: Upload Backend Artifacts
uses: actions/upload-artifact@v4
with:
name: my-artifact-backend-${{ matrix.arch }}
path: dc-back-${{ matrix.arch }}
docker-setup:
runs-on: ubuntu-latest
needs: [ build-frontend, build-backend ]
steps:
- name: Checkout code Now Code
uses: actions/checkout@v3
- name: Download Backend Artifacts
uses: actions/download-artifact@v4
with:
pattern: my-artifact-backend-*
merge-multiple: true
path: dc-back
- run: ls -R dc-back
- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v3.0.0
- name: Docker Login
uses: docker/login-action@v3.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker images
uses: docker/build-push-action@v5.0.0
with:
context: .
file: ./docker/Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/dockercopilot:latest-dev
push: true