Release 1.6.0 #36
Workflow file for this run
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: Publish release Docker image | |
on: | |
release: | |
types: | |
- created | |
env: | |
IMAGE_NAME: metrik | |
jobs: | |
test-build-push-image: | |
name: 'Run tests, build artifacts and push image' | |
runs-on: ubuntu-latest | |
services: | |
mongo: | |
image: mongo:4.4-bionic | |
env: | |
TZ: "Asia/Shanghai" | |
ports: | |
- 27017:27017 | |
steps: | |
- name: Setup timezone | |
run: sudo timedatectl set-timezone "Asia/Shanghai" | |
- uses: actions/checkout@v2 | |
- name: Setup Java JDK | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'adopt' | |
java-package: 'jdk' | |
java-version: '11' | |
check-latest: true | |
- name: Cache Gradle packages | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Run backend tests | |
uses: ./.github/actions/backend_test | |
with: | |
working-dir: ./backend | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Cache Node.js packages | |
uses: actions/cache@v2 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Run frontend tests | |
uses: ./.github/actions/frontend_test | |
with: | |
working-dir: ./frontend | |
- name: Collect artifacts | |
run: | | |
ARTIFACT_DIR="./ci/artifacts" | |
mkdir -p $ARTIFACT_DIR/backend | |
mkdir $ARTIFACT_DIR/frontend | |
cp -rp ./frontend/dist $ARTIFACT_DIR/frontend/ | |
cp -p ./backend/build/libs/metrik-backend-*.jar $ARTIFACT_DIR/backend/ | |
cp -p ./backend/run.sh $ARTIFACT_DIR/backend/ | |
- name: Install AWS CLI | |
run: | | |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
unzip awscliv2.zip | |
sudo ./aws/install --update | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
- name: Login to AWS ECR | |
run: aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ secrets.AWS_PUBLIC_ECR_ACCOUNT_URL }} | |
- name: Build and push Docker image | |
run: | | |
IMAGE_ID=${{ secrets.AWS_PUBLIC_ECR_ACCOUNT_URL }}/${{ secrets.AWS_PUBLIC_ECR_REPO }} | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
docker build . --file Dockerfile --tag $IMAGE_ID:latest --tag $IMAGE_ID:$VERSION --label "runnumber=${GITHUB_RUN_ID}" --label "hash=${GITHUB_SHA}" | |
IFS="," read -ra DOCKER_TAGS <<< "latest,$VERSION" | |
for tag in "${DOCKER_TAGS[@]}"; do | |
docker push $IMAGE_ID:$tag | |
done | |
working-directory: ./ci | |
# - name: Build and push Docker image | |
# run: | | |
# IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | |
# | |
# # Change all uppercase to lowercase | |
# IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
# | |
# # Strip "v" prefix from tag name | |
# VERSION=$(echo ${{ github.event.release.tag_name }} | sed -e 's/^v//') | |
# | |
# docker build . --file Dockerfile --tag $IMAGE_ID:latest --tag $IMAGE_ID:$VERSION --label "runnumber=${GITHUB_RUN_ID}" --label "hash=${GITHUB_SHA}" | |
# | |
# IFS="," read -ra DOCKER_TAGS <<< "latest,$VERSION" | |
# for tag in "${DOCKER_TAGS[@]}"; do | |
# docker push $IMAGE_ID:$tag | |
# done | |
# working-directory: ./ci |